Subject: Re: static against non-static
From: Paul Freeman (firstname.lastname@example.org)
Date: Wed Oct 16 2002 - 10:14:18 EDT
Hi Class -
One of the students raised an interesting question.
>I went throught most of the frist part of aosd.ppt
>and now I am going through the programers guide.
>It was mentioned that the aspect are essencially Singletons.
>So, does it matters if I declare methods or members
>in an aspect static or not?
The answer is yes there is a difference. When you declare a singleton
Aspect in an application:
there is an instance of this Aspect for the entire application. It can
be referenced at any time with the static method inherited by all
singleton aspects "instanceOf()". This returns a reference to an
instantiated aspect object. So, in the above example to get the
instance of aspect A that exists for the entire program, you could use
the following code:
A a = A.instanceOf();
now you can call the non-static methods of A on the object a. If you
wish to call the static methods of aspect A, you can call them at any
time just as instanceOf() was called above.
Aspects do not have to be declared as singleton aspects however. There
can be more than one instance of an Aspect in an application. In this
case, Aspects are declared in a way in which an instance is instantiated
and related specifically to another object in the application. You can
get the aspect related to an object with the static method inherited by
all non-singleton aspects "instanceOf(Object objRelatedTo)", i.e.
A a = A.instanceOf(someObj);
Since there are multiple instances of aspect A in an application, there
will of course be a big difference between calling a Static or
Non-Static method of A.
Hope this helps,
This archive was generated by hypermail 2b28 : Wed Oct 16 2002 - 10:23:57 EDT