[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-dev] Aspect per object instance
|
Quick notes:
- consider declaring the methods on the target class instead (untested):
aspect A {
public void Subject.notifyObservers(Event ev) { ... }
after(Subject o,Event e) returning : updateObserver(o,e) {
o.notifyObservers(e);
}
}
- or, do pertarget aspects work for you?
- See also the patterns implemented by Jan Hanneman
(need to search the old users@xxxxxxxxxxx for the link)
and the observer example in the aspectJ distribution,
if you haven't already.
Wes
"Enrique J. Amodeo Rubio" wrote:
>
> Hi,
>
> I have a question about aspect instantiation, how can I have an aspect
> instance per each object of a determinated class? In this way we could
> create an aspect like the following (some sintax, like perobject are
> invented):
>
> public abstract aspect SubjectObserverProtocol perobject(Subject+)
> {
> private Set observers = new HashSet();
> public void notifyObservers(Event ev)
> {
> Iterator it=observers.iterator();
> while(it.hasNext())
> {
> update((Observer)it.next(),ev);
> }
> }
>
> public void addObserver(Observer o)
> {
> observers.add(o);
> }
>
> // follows point-cuts and advice to capture when is necesary to
> // update the subject.
>
> pointcut abstract updateObserver(Subject o,Event e);
> protected abstract void update(Observer o,Event ev);
> void after(Subject o,Event e) : updateObserver(o,e)
> {
> o.aspectOf().notifyObservers(e);
> }
> }
>
> It should be a concrete aspect implementing updateObserver and update
> method for each. Subject and Observer are empty interfaces. An important
> point is avoiding collisions.
>
> Does anybody know how to do this with aspectJ? Is necesary add more
> functionality like the perobject keyword? Is there any work-around or
> idiom? I feel there should be a good way to implement this kind of
> functionality in an elegant way using aspectJ.
>
> Thank you in advance,
>
> Enrique J. Amodeo Rubio
>
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-dev