I tend to use private properties instead of private fields because they can be extended if necessary, so most of my model classes look like this:
public class MyClass
{
public MyClass(string name)
{
this.Name = name;
}
private string Name { get; set; }
private ISomeInterface SomeInterface { get; set; }
private bool IsSomething { get; set; }
public void Method(int parameter) { ... }
}
In other words, I usually replace private fields by private properties. Even inside the class context, properties are used, not fields. Most of them are auto-properties. Often I found out that my classes have no private fields at all (well, only the automatic backing fields for automatic properties).
I found this useful if you want to change the behavior (fields don't allow such flexibility).
I would like to know it this is a bad practice.
- If it is a bad practice: WHY?
- If it's not: do you think that I should use the "this" keyword inside the class to improve legibility?
Thanks!