There are some lightweight ways of handling this using roles.

 

Person

            instanceVariables: roles

 

aPerson roles add: Human new; add: Ninja new.

 

There are a number of roles implementations.  One based on doesNotUnderstand which runs through the roles collection and passes the called but not understandable message to each instance.  Some implementations will return a collection of responses if multiple roles answer the same message, and this can get kinda tricky if you don’t know how to watch for it.  You can also define a specific interface to your methods by specifically implementing your methods on Person to look for a role before forwarding the method and handling the call if it does not.

 

For Example:

 

Person >> killSilently

            aPerson hasNinjaRole ifTrue: [^self ninjaRole killSilently].

            aPerson hasHumanRole ifTrue: [^self humanRole killSilently].

            aPerson handleKillingRequestWithMoreSleepAndExercise.

 

Ninja >> killSilently

            “walk on rice paper leaving no trace then you will be ready”

            self doSilentKilling

 

Human >> killSilently

            “humanity wins”

            self tryToKill.

            self goToPoliceStation.

            self confess.

 

I’m not saying I like roles.  I just thought I’d mention more options.

 

Ron Teitelbaum

President / Principal Software Engineer

US Medical Record Specialists

[EMAIL PROTECTED]

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Gorsuch
Sent: Monday, November 13, 2006 3:56 PM
To: A friendly place to get answers to even the most basic questions aboutSqueak.
Subject: Re: [Newbies] How to squeeze Multiple Inheritance into Squeak ?

 

Here's an idea:

I have a Person class, but I need him to inherit traits that the Human class has and the Ninja class has.

Is that sufficient?

On 11/13/06, Michael Haupt <[EMAIL PROTECTED]> wrote:

Hi Warakom,

On 11/13/06, Warakorn Paphrawat <[EMAIL PROTECTED]> wrote:
> Sadly enough the possibility of Multiple Inheritance in Squeak would greatly
> benefit me in my current Squeak project ?

what exactly is the characteristic in your project that imposes this
requirement on it? Why do you need multiple inheritance? What would
you use it for?

I'd recomment looking at traits first, but without knowing what
exactly you are trying to achieve, I cannot say much more. :-)

Best,

Michael
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

 

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to