Class data members
-
When should a class access its own data members through a property rather than directly access them?
-
When should a class access its own data members through a property rather than directly access them?
Only when you really need to. Accessing through the property involves more work in the IL than actually directly accessing them.
Deja View - the feeling that you've seen this post before.
-
Only when you really need to. Accessing through the property involves more work in the IL than actually directly accessing them.
Deja View - the feeling that you've seen this post before.
-
When should a class access its own data members through a property rather than directly access them?
-
When should a class access its own data members through a property rather than directly access them?
When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic (:~) wherever you directly change the property value.
-
When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic (:~) wherever you directly change the property value.
-
When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic (:~) wherever you directly change the property value.
Brady Kelly wrote:
When your property methods contain logic that maintains some other value when the property changes. The alternative is to duplicate that logic ( [Unsure] ) wherever you directly change the property value.
That's why I would always access a data member through the property, if one is provided by the class designer. Even if it appears that accessing the member directly would accomplish the same thing, you don't know what what might be added to the property later. That's what properties are for; to provide controlled access to a data member. Why circumvent it? Robert C. Cartaino
-
When should a class access its own data members through a property rather than directly access them?
Just when they need to.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham