in reply to Re: (OT) OOUI: multiple views in an object.
in thread (OT) OOUI: multiple views in an object.

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.

Replies are listed 'Best First'.
Re: Re: Re: (OT) OOUI: multiple views in an object.
by castaway (Parson) on Nov 01, 2003 at 11:21 UTC
    Yup, I thought that's what he said too.. My point was more, how the hell does the coffee machine know how to refill itself? (Talking about a home-version, not an industrial version here, see below..)

    There are times when you want autonomous objects, and times when you want them just as parts of other apps..

    C.