I\'m reading the book \"Clean Code\" and am struggling with a concept. When discussing Objects and Data Structures, it states the following:
Generating public accessors with private fields establishes a contract between user code and your class. Ideally, this contract should not change over revisions to code.
In C#, the way to enforce contract compliance is with an interface
. Interfaces will allow you to specify required method and property implementations, but does not allow for fields.
Moreover, in various points of .NET, properties are often preferred over fields. e.g. PropertyGrid control only enumerates properties, ASP.NET MVC model classes require properties, etc.