[Newbies] How to squeeze Multiple Inheritance into Squeak ?
Ron at USMedRec.com
Mon Nov 13 22:36:25 UTC 2006
There are some lightweight ways of handling this using 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.
Person >> killSilently
aPerson hasNinjaRole ifTrue: [^self ninjaRole killSilently].
aPerson hasHumanRole ifTrue: [^self humanRole killSilently].
Ninja >> killSilently
"walk on rice paper leaving no trace then you will be ready"
Human >> killSilently
I'm not saying I like roles. I just thought I'd mention more options.
President / Principal Software Engineer
US Medical Record Specialists
Ron at USMedRec.com
From: beginners-bounces at lists.squeakfoundation.org
[mailto:beginners-bounces at lists.squeakfoundation.org] On Behalf Of Michael
Sent: Monday, November 13, 2006 3:56 PM
To: A friendly place to get answers to even the most basic questions
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 <mhaupt at gmail.com> wrote:
On 11/13/06, Warakorn Paphrawat <warakorn_paphrawat at yahoo.com> wrote:
> Sadly enough the possibility of Multiple Inheritance in Squeak would
> 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. :-)
Beginners mailing list
Beginners at lists.squeakfoundation.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners