|
Re: sending #respondsTo:: msg#00092lang.smalltalk.squeak.beginners
Responds to certainly has its place, but you want to favor polymorphism first. Say you need to move some animals around but some of the animals are fish and some are birds. You might have client code that looks like this (but it would be bad) anAnimal respondsTo: #swim ifTrue: [anAnimal swim] ifFalse: [anAnimal fly] It would be better to come up with a common message name and just send the message anAnimal move This would require two methods: Fish>>#move Bird>>#move The beauty of this is that your client code doesn't change if you've got a flightless bird subclass (Penguin) or a flying fish... (I've never worked on zoological code, but I have refactored code like the above for a company with three different billing systems that had incompatible protocols.) On Fri, Apr 11, 2008 at 7:48 PM, itsme213 <itsme213@xxxxxxxxxxx> wrote: > Is it considered bad practice to use #respondsTo:? If so, why? > > Lint flags it as a "questionable" message. > > Thanks - Sophie > > > > _______________________________________________ > Beginners mailing list > Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx > http://lists.squeakfoundation.org/mailman/listinfo/beginners >
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | sending #respondsTo:, itsme213 |
|---|---|
| Next by Date: | Squeak networking, Herbert König |
| Previous by Thread: | sending #respondsTo:, itsme213 |
| Next by Thread: | Squeak networking, Herbert König |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |