[aspectc-user] run-time aspects

Jamal Siadat siadat at cpsc.ucalgary.ca
Tue Nov 29 00:50:21 CET 2005


Hi,
yes that helped to a great extent, but is there any way to "introduce" a
class which is a sub-class of another inside an aspect? In our example can
I create B inside an aspect say:

Aspect B : public A {

// the rest of  is defined here
};

or alternatively:

Aspect extend : public A {
// create new class B in here which will be a sub-class of A?
};

Is any of those two methods possible and will it result in me being able
to instantiate objects of type B?

Thanks,


> Hi,
>
> the new members of A that are introduced by B and C become ordinary
> members after weaving the aspects. There are neither base classes nor
> derived classes generated. However, you could do something like this:
>
> class B {
>    int y;
> };
>
> aspect B_in_A {
> public:
>    advice "A" : baseclass (B);
> };
>
> This will make the "class B" a public base class of A. You could then
> instantiate B objects without the rest of A.
>
> Alternatively, you could also derive the classes B and C from A. It
> sounds as if this is what you want. However, you don't need any aspect
> for this. If B and C use virtual inheritance, you could even create a
> class that inherits from B and C that contains only one instance of A.
> Of course, you could introduce the base class relationship between B and
> A as well as C and A by baseclass introduction as shown above.
>
> Does that help?
>
> Olaf
>
>
> Jamal Siadat wrote:
>> Hi,
>> Here is the second part:
>> if so when I am running the
>>>>program
>>>>can I have:
>>>>B b;
>>>>b.y=5;
>>>>If not, what alternatives would I have so I can just create B type  at
>>>>run-time like above?
>>
>> Which means I would like to create and access objects "B" or objects of
>> "C" since I assume B and C will be created as sub-classes of A when
>> compiled. If not What other alternatives do I have to compile two
>> aspects
>> to extend a class and then create objects of each ?
>>
>> Thanks,
>>
>>
>>
>>>Hi,
>>>
>>>first of all, there are a few syntax errors in your code. For instance,
>>>aspect B should look like this:
>>>
>>>aspect B {
>>>   pointcut add() = "A";
>>>   advice add() : int y;
>>>};
>>>
>>>Besides this syntax problem, you could compile both aspects together
>>>with your component code. The weaver will introduce the new members "y"
>>>*and* "Q" into the class "A".
>>>
>>>Introductions are a means to implement *static* crosscutting. Therefore,
>>>all instances of A will contain both new members.
>>>
>>>I'm sorry, but I don't understand the second part of your question: "If
>>>the answer to the first part is yes Then is there any way create objects
>>>of A, B or C independently?". Could you try to explain it again or is my
>>>answer already sufficient?
>>>
>>>- Olaf
>>>
>>>
>>>Jamal Siadat wrote:
>>>>Hi All,
>>>>I just have a couple of questions I was wondering if you may address
>>>> for
>>>>me please:
>>>>first Does AspectC++ suopport the expansion of a particular class by
>>>> two
>>>>different aspects that may be compiled simuntaniously?
>>>>for instance is it possible to have a class "A" and use aspects "B" and
>>>>"C" to add some methods/variables to it. ( each of A and B add
>>>> different
>>>>methods and variables).
>>>>
>>>>If the answer to the first part is yes Then is there any way create
>>>>objects of A, B or C independently? Here is an example:
>>>>
>>>>class A{
>>>>A();
>>>>~A();
>>>>int a;
>>>>void b();
>>>>}
>>>>
>>>>aspect B {
>>>>pointcut add() : "A";
>>>>add (): int y;
>>>>//adding integer y to class A
>>>>};
>>>>
>>>>aspect C {
>>>>pointcut addition() : "A";
>>>>addition (): bool Q;
>>>>//adding bolean Q to class A
>>>>};
>>>>
>>>>Can I compile B and C simuntaniously? if so when I am running the
>>>>program
>>>>can I have:
>>>>B b;
>>>>b.y=5;
>>>>If not, what alternatives would I have so I can just create B type  at
>>>>run-time like above?
>>>>
>>>>Thanks all,
>>>>Jamal
>>>>
>>>>_______________________________________________
>>>>aspectc-user mailing list
>>>>aspectc-user at aspectc.org
>>>>http://www.aspectc.org/mailman/listinfo/aspectc-user
>>
>>
>> _______________________________________________
>> aspectc-user mailing list
>> aspectc-user at aspectc.org
>> http://www.aspectc.org/mailman/listinfo/aspectc-user
>





More information about the aspectc-user mailing list