Good point with the Salary field. That could be considered a part of the public interface of the Empoyee class. And querying the Salary or Name of an Employee in order to display them or something, that would be okay. But as soon as you start comparing the Salary with something else that was taken out from inside the object, you're losing cohesion.
After I read about this the first time, I thought I'd try to follow the sentiment of the principle, and that has resulted in better designed OO code, without me doing much designing. It just falls out of the principle.
The wiki page really states the principle so much more succinct than what I wrote above: "It is okay to use accessors to get the state of an object, as long as you don't use the result to make decisions outside the object."
Something I've noticed is that sometimgs it's vague where a piece of logic belongs: which class should implement the method, taking a property from another object as a parameter.
For example: "is the Employee's Salary above average in her Department?" Should that go in the Employee class, or the Department class? It depends on the rest of the design.
/J
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.