If someone writes code so that an internal variable $_fields is accessible without using getter/setter methods, is there a proper term used to describe that?
Something polite enough to use with management :)
|
If someone writes code so that an internal variable $_fields is accessible without using getter/setter methods, is there a proper term used to describe that? Something polite enough to use with management :) |
|||||||||||||||
|
|
Exposing ones private members is never a good thing in polite society... This practice is the lack of/poor encapsulation. |
|||||||||||||||||||||
|
|
It's called "not following a specific coding standard". The OP wrote:
That might be against your standard, and (thus) it might be code smell. But it is not necessarily poor encapsulation. Exposing an internal (as in "only of internal use") variable over getter and setters to the outside world would be even worse. The question is: should If so, we have a case where you would add getter/setter methods. These methods do not encapsulate anything but the fact that If The issue of encapsulation is entirely orthogonal to this. Violating encapsulation is absolutely possible with getters and setters. It's even easier to slip into, because most people's alarm bells don't ring when they see a bunch of getters and setters - code that's seemingly following best practices. Code, that might very well introduce much more dependencies on internal implementation details than a variable called I'm a fan of bad analogies: Calling that poor encapsulation is like calling someone who holds a gun a murderer. |
|||
|
|
|
if your setter/getter methods are nothing more than
then just making a pubic variable is just saving some typing outside of a few edge cases where the difference matters. |
|||||||
|
|
I've heard the term "naked object" before. |
|||||||||
|
|
Its called a property bag. Usually it is used to hold a set of maybe related properties (were each may potentially be a class object that has appropriate access specifiers or not). But the surrounding structure is just a bag of properties. |
|||
|
|
|
Besides the lack of encapsulation already mentioned by Oded, depending on the programming language and its paradigms it could also be "plain old data" (where it isn't necessarily an antipattern or code smell). |
|||
|
|