The interface can be used to enforce methods, but they must be publicly available.
What if I want to use private methods?
Update: this is not about preventing the call, but to ensure that the private method has been DONE.
Therefore, I do not want to use the interface as such. I want to impose some kind of coding style on the team.
. ( , ) , :
public abstract class A { protected abstract void Foo(); } public class B : A { protected override void Foo() { } }
, Foo B Foo() B.
Foo
B
Foo()
Edit:
, - , , , : , :
public interface IFooWorker { void DoWork(); int CalculateSomething(); } public class Foo { private FooWorker _worker; private int _currentValue; private string _workStatement; public Foo() { _worker = new FooWorker(this); } private class FooWorker : IFooWorker { private Foo _outer; public FooWorker(Foo foo) { _outer = foo; } public void DoWork() { _outer._currentValue = CalculateSomething(); _outer._workStatement = "I did work"; } public int CalculateSomething() { return 42; } } }
? , , , . , , , , , , .
, . , ... - , API . , .
" " ? ?
, , ", " - .
, , /Func/Action . , , . , , ... .. , -.
, , . , , , , , , , . , . , .NET, , , , .
"private", , , , OO.
!
"private", .
: http://msdn.microsoft.com/en-us/library/ms173157.aspx
- , . , - : .
, . , .
This does not make sense, since the private method declared in the interface cannot be called.