Re: wondering ...

Jon Tirsen <[email protected]> Sun, 29 Feb 2004 17:35:37 +0000
Newsgroups gmane.comp.java.nanning.devel
Message-ID <[email protected]>
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"=20
modularization technique. With this I mean that the client code *is not=20
aware of it being affected by and aspect*.

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

There is no automatic way of getting hold of a "parent" component in=20
PicoContainer. Instead you need to set the parent container on the=20
children as they are provided in the constructore. Ie.: your constructor=20
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=20
be used in this situation. Just use PicoContainer. Nanning is better=20
used for cross-cutting behaviour, it's not designed to be an object=20
composition/assembly technique. PicoContainer is designed for exactly=20
that purpose.

Hope this helps,
Jon

roger menday wrote:

>Thanks, that's very helpful !=20
>
>... 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.=20
>
>Which is the best path for this, nanning, picocontainer, a combination
>of both ?=20
>
>Thanks,=20
>
>Roger
>
>On Wed, 2004-02-25 at 11:45, Jon Tirs=C3=A9n wrote:
> =20
>
>>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 <[email protected]> skrev: >=20
>>   =20
>>
>>>Hi,=20
>>>
>>>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 ?=20
>>>
>>>Roger
>>>
>>>
>>>_______________________________________________
>>>nanning-dev mailing list
>>>[email protected]
>>>
>>>     =20
>>>
>>http://lists.codehaus.org/mailman/listinfo/nanning-dev
>>
>>H=C3=B6strusk och gr=C3=A5 moln - k=C3=B6p en resa till solen p=C3=A5 Y=
ahoo! Resor p=C3=A5 adressen http://se.docs.yahoo.com/travel/index.html
>>_______________________________________________
>>nanning-dev mailing list
>>[email protected]
>>http://lists.codehaus.org/mailman/listinfo/nanning-dev
>>
>>   =20
>>
>
>_______________________________________________
>nanning-dev mailing list
>[email protected]
>http://lists.codehaus.org/mailman/listinfo/nanning-dev
>
> =20
>