Are protected members/fields really that bad?

前端 未结 6 1600
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 02:33

Now if you read the naming conventions in the MSDN for C# you will notice that it states that properties are always preferred over public and protected fields. I have even

6条回答
  •  盖世英雄少女心
    2020-11-29 02:59

    It actually depends on if your class is a data class or a behaviour class.

    If you keep your behaviour and data separate, it is fine to expose the data of your data classes, as long as they have no behaviour.

    If the class is a behaviour class, then it should not expose any data.

提交回复
热议问题