The interface defines an open API. If the public API contains only getter, then you define only getter in the interface:
public interface IBar { int Foo { get; } }
The private setter is not part of the public api (like any other private member), so you cannot define it in the interface. But you can add any (private) members to the implementation of the interface. In fact, it does not matter if the setter is implemented as open or closed, or if there will be a setter:
public int Foo { get; set; } // public public int Foo { get; private set; } // private public int Foo { get { return _foo; }
The setter is not part of the interface, so it cannot be called through your interface:
IBar bar = new Bar(); bar.Foo = 42; // will not work thus setter is not defined in interface bar.Poop(); // will not work thus Poop is not defined in interface
Sergey Berezovskiy Aug 15 '13 at 9:38 on 2013-08-15 09:38
source share