Hello, Can anyone give me a simple Traits example? I am trying to figure out if it would be useful for me in the context of developing Aida applications.
In Aida, a WebApplication observes a domain model object. Let's call it WebAppModel.
Of course, you could subclass ANY object to create your WebAppModel, but I still want it to know how to do certain things, like start and stop itself.
In other words, I might have one WebAppModel that subclasses Object, and another that subclasses OrderedCollection, but I don't want to teach them both how to start or stop each time I create a new one, and it seems less elegant to subclass everything from a WebAppModel base class and then include the actual objects they model as instance variables.
Does this make sense or am I missing some other fundamental concept, and is this what Traits are for?
Thanks,
Rob Rothwell
Hi Rob,
What you say seems to make sense, but it is hard to tell without looking at some code.
There are some simple examples of traits in Chapter 5 of Squeak by Example.
http://SqueakByExample.org/SBE.pdf
- on
On Mar 17, 2008, at 2:37, Rob Rothwell wrote:
Hello,
Can anyone give me a simple Traits example? I am trying to figure out if it would be useful for me in the context of developing Aida applications.
In Aida, a WebApplication observes a domain model object. Let's call it WebAppModel.
Of course, you could subclass ANY object to create your WebAppModel, but I still want it to know how to do certain things, like start and stop itself.
In other words, I might have one WebAppModel that subclasses Object, and another that subclasses OrderedCollection, but I don't want to teach them both how to start or stop each time I create a new one, and it seems less elegant to subclass everything from a WebAppModel base class and then include the actual objects they model as instance variables.
Does this make sense or am I missing some other fundamental concept, and is this what Traits are for?
Thanks,
Rob Rothwell _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
On Mon, Mar 17, 2008 at 7:07 AM, Oscar Nierstrasz < oscar.nierstrasz@gmail.com> wrote:
Hi Rob,
What you say seems to make sense, but it is hard to tell without looking at some code.
There are some simple examples of traits in Chapter 5 of Squeak by Example.
Thanks, Oscar...and there it was, right in front of me all along.
"A trait is a collection of methods that can be included in the behaviour of a class without the need for inheritance. This makes it easy for classes to have a unique superclass, yet still share useful methods with otherwise unrelated classes."
This may just be what I was looking for!
Thanks again,
Rob
beginners@lists.squeakfoundation.org