roger menday | 25 Feb 2004 11:19
Picon
Picon
Favicon

wondering ...


Hi, 

Although, I am new to nanning (and AOP generally), recently I have read
quite a bit, but cannot sufficiently answer one particular question ::

I thinking how Mixins might help my coding ::  it seems to me that the
Mixin would be useful (even without the AOP functionality), but I might
need the Mixin to have access to the state of the object is it being
MixedIn to. Is this something that is usual/ supported, or am I barking
up the wrong tree ? 

Roger
Jon Tirsén | 25 Feb 2004 11:45
Picon
Favicon

Re: wondering ...

Sure, that is common if you use mixins a lot. There's
a simple way of doing it in Nanning:
(MainObject) Aspect.getThis()

To explain:
If you have a mixin MyMixin and a main object
MainObject then in MyMixin you can do Aspect.getThis()
which will return you the currently executing proxy.
You can cast it both to MyMixin and MainObject.

It's possible in for example Dynaop too but the
mechanics are slightly different.

Hope this helps,
Jon

 --- roger menday <r.menday <at> fz-juelich.de> skrev: > 
> Hi, 
> 
> Although, I am new to nanning (and AOP generally),
> recently I have read
> quite a bit, but cannot sufficiently answer one
> particular question ::
> 
> I thinking how Mixins might help my coding ::  it
> seems to me that the
> Mixin would be useful (even without the AOP
> functionality), but I might
> need the Mixin to have access to the state of the
> object is it being
(Continue reading)

roger menday | 25 Feb 2004 12:26
Picon
Picon
Favicon

Re: wondering ...


Thanks, that's very helpful ! 

... as a continuation of this question, suppose I wanted to achieve a
similar functionality with picocontainer. I want to use a 'aggregated
component', which declares in the constructor it's individual
components. The methods in these individual components should operate on
state stored in the main component. Is it possible to gain access to the
state of the 'parent' component in picocontainer ? Am I confusing things
here ?!?

I am viewing the composite components as Mixins to the main aggregating
component. Then, I would like to use picocontainer as a lightweight
holder of currently running instances of the 'aggregated component'
service. 

Which is the best path for this, nanning, picocontainer, a combination
of both ? 

Thanks, 

Roger

On Wed, 2004-02-25 at 11:45, Jon Tirsén wrote:
> Sure, that is common if you use mixins a lot. There's
> a simple way of doing it in Nanning:
> (MainObject) Aspect.getThis()
> 
> To explain:
> If you have a mixin MyMixin and a main object
(Continue reading)

Jon Tirsen | 29 Feb 2004 18:35

Re: wondering ...

Sorry for answering so late. I've been back in Sweden for a visit.

The most important thing to understand about AOP is that it's a "push" 
modularization technique. With this I mean that the client code *is not 
aware of it being affected by and aspect*.

So your approach (declaring in the main class the mixins that the class 
needs) would work but it would not be AOP. I think in this case I would 
probably use a more traditional OOP approach, see Gang-of-Four Composite 
pattern.

There is no automatic way of getting hold of a "parent" component in 
PicoContainer. Instead you need to set the parent container on the 
children as they are provided in the constructore. Ie.: your constructor 
would look something like:
public void Parent(Child1 c1, Child2 c2) {
  // calling super/this and other initialization code
  c1.setParent(this);
  c2.setParent(this);
}

Nanning is a bit too "magical" (that is the code is not clear enough) to 
be used in this situation. Just use PicoContainer. Nanning is better 
used for cross-cutting behaviour, it's not designed to be an object 
composition/assembly technique. PicoContainer is designed for exactly 
that purpose.

Hope this helps,
Jon

(Continue reading)


Gmane