[Tutor] Object Oriented References? and a couple of question s <--LONG
Steven Burr
sburr@mac.com
Sun, 12 Aug 2001 15:54:08 -0700
On Saturday, August 11, 2001, at 11:25 AM, alan.gauld@bt.com wrote:
[snip]
> Thus
>
> cook = Cook()
> pantry = Pantry()
> cook.makeMeal()
>
> And the makeMeal method might look like this:
>
> class Cook:
> def makeMeal(meal)
> ingredients = pantry.gather()
> for item in ingredients
> item.sift()
> return meal.bake(ingredients)
Don't you lose polymorphism by hard-coding a call to a specific
instance's method? Wouldn't it be more consistent with OO design to
allow "makeMeal" to call the "gather" method of any object that
implements it? For example:
class Cook:
def makeMeal(self, meal, supplier):
ingredients = supplier.gather(meal)
. . .
cook1 = Cook()
source1 = Pantry()
lunch = cook1.makeMeal("tuna fish sandwich", source1)
cook2 = Cook()
source2 = CheeseShop()
snack = cook2.makeMeal("camembert and crackers", source2)
for-some-reason-i'm-feeling-a-might-peckish'ly yours, sburrious