For your first point, my take on the article was that his preferred method for dealing with your coffee machine problem would be to just have a method that does what you need it to, say, $coffee_machine->refill(); Thus the specific implemenations of the coffee, how it needs to refill, etc etc are all hidden from the programmer. Other wise you would end up with something like:
$cm->{temp}=150;
$cm->{amount}=100;
$cm->{heat_time}=5;
And so on and so forth. Having just one method completely hides the implementation details of whatever you need to do. Otherwise you just have a datastructure, not an object.
As to your second problem, in this case I would have three objects. A coffee machine object, a coffee object, and a cup object. Then you can have your coffee machine create new coffee objects and then add them to the cup object. Then you could change every single thing about coffee and cups and still be able to say
my $cm=new Coffee_Machine;
my $coffee=$cm->gimme_coffee();
my $cup=new Cup($coffee);
And never, ever have to change those lines of code.
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.