ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] Object Oriented References? and a couple of question s <--LONG
by Steven Burr other posts by this author
Aug 12 2001 10:54PM messages near this date
RE: [Tutor] Object Oriented References? and a couple of question s <--LONG | [Tutor] OOP book
On Saturday, August 11, 2001, at 11:25 AM, alan.gauld@[...].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

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:

Steven Burr

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved