[aspectc-user] construction advice
gduzan at bbn.com
Fri May 20 16:00:16 CEST 2005
In Message <428D8B93.7000309 at informatik.uni-erlangen.de> ,
Olaf Spinczyk <Olaf.Spinczyk at informatik.uni-erlangen.de> wrote:
=>Adolfo Gustavo Serra Seca Neto wrote:
=>> Is it possible to change the object "returned" by a constructor?
=>> Suppose there is the following base code:
=>> Formula *f1 = new Formula("A");
=>> Formula *f2 = new Formula("A");
=>> I want an aspect such that f1==f2. This is related to the Flyweight
=>> Is this possible?
=>you could use an introduction to insert an 'operator new()' into Formula.
I don't think this would necessarily produce the desired result. The
result of operator new is the storage to use. If you return the same
storage as for a previous object, the constructor for the new object
will still execute, writing to the same storage as the previous object,
potentially resulting in chaos. It might be possible to avoid this with
careful storage management, but it would likely be messy to try to apply
as an aspect to arbitrary classes.
On the other hand, implementing the FLyweight pattern as an aspect
does sound like a very intersting idea if it can be made to work.
More information about the aspectc-user