I’m aware of these two questions which explain why I can’t have a protected/private method in an interface, what I’m trying to work out is how to control from where my methods are called, briefly:
public class EditField : IEditField { public EditField() {} public EditField(IStateMachine stateMachine) {} public void Action_Commit() {} public void Action_Undo() {} }
Consumers can use the default IStateMachine, or roll their own.
I was wondering if there is any way to ensure that Action_ methods are only called from within an IStateMachine, so that consumers don’t start messing around with state stuff. I suspect there’s no way of doing this, but wondered if I’m missing something. I’m not a Design Pattern guru.
While you can’t have access modifiers on interfaces, but here’s one way to hide the members, yet make them accessible to IStateMachine implementors.