Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Aspect per object instance

Lesiecki Nicholas wrote:

Wes was right to point you at Jan Hanneman's implementation, which solves
this problem rather elegantly.

You can find information on the Design Patterns project at:

http://www.cs.ubc.ca/~jan/AODPs/

Also, my forthcoming book Matering AspectJ
(http://www.amazon.com/exec/obidos/tg/detail/-/0471431044/)
contains a full writeup on this particular pattern, including a sample
application to the problem of cache invalidation.

Cheers,

Nick

--- "Enrique J. Amodeo Rubio" <eamodeorubio@xxxxxxxxxxxxxx> 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-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Thanks, you save me the time for looking for the pattern in the old newsgroup, I'll read your book too.



Back to the top