Board index » delphi » Tricky Question about howking constructors

Tricky Question about howking constructors


2005-02-10 12:28:42 AM
delphi164
Hi,
I've been giving the following idea some thought but I'd really
appreciate your insights.
I coded an OPF. Instead of objects the programmers uses proxys that
contains the real subject. To create a new object inside the framework (and
persistent) you use a Factory. Something like this:
var
aClient : TClient
Begin
aClient := HecFactory.CreateNewClient;
..
Here a Client actually references a ClientProxy but that is supposed to be
"transparent" to the programmer.
The thing is like this. I managed to hook the constructor using some
libraries that modifies the assembler in memory or something. Using those
libraries I can make something like:
Client := TClient.Create;
But when you see the client Classname it result that it is actualy a proxy.
In that way the creation if even more transparent. You can add a unit to
your project have persistent objects and comment that unit and the code
would still work.
I tested troughtly and it worked perfectly but...The ting is. To do that
you hace to modify de ASM in memory with this libraries.
I have to decide if I hace to implement it or leave the factory as it is.
What is your advice. The procedure to do it is very strange so I cannot make
my mind.
I hope I explained my point. If I missed something or if there is some
detail missing please ask.
What is your advice?
Esteban Calabria
 
 

Re:Tricky Question about howking constructors

By the way...
What I did is something similar (in result, not in method) to overriding the
ClassLoader in Java.
 

Re:Tricky Question about howking constructors

Hechicero writes:
Quote
Hi,
I've been giving the following idea some thought but I would
really appreciate your insights.
I coded an OPF. Instead of objects the programmers uses proxys
that contains the real subject. To create a new object inside the
framework (and persistent) you use a Factory. Something like this:

var
aClient : TClient
Begin
aClient := HecFactory.CreateNewClient;
..

Here a Client actually references a ClientProxy but that is supposed
to be "transparent" to the programmer.

The thing is like this. I managed to hook the constructor using some
libraries that modifies the assembler in memory or something. Using
those libraries I can make something like:

Client := TClient.Create;

But when you see the client Classname it result that it is actualy a
proxy. In that way the creation if even more transparent. You can add
a unit to your project have persistent objects and comment that unit
and the code would still work.
So you're wondering whether you should keep
aClient := HecFactory.CreateNewClient;
or do some "magic" asm stuff to enable code like:
Client := TClient.Create;
?
Use the factory! It is more powerful because you can have multiple
implementations of the factory, one factory returning proxies, another
returning the "real" objects, so it is just as transparent (and is a
common pattern). The asm alternative sounds *very* ugly. :-)
Cheers,
Jarle
 

Re:Tricky Question about howking constructors

In article <420a46b3$XXXX@XXXXX.COM>,
XXXX@XXXXX.COM says...
Quote
Use the factory! It is more powerful because you can have multiple
implementations of the factory, one factory returning proxies, another
returning the "real" objects, so it is just as transparent (and is a
common pattern). The asm alternative sounds *very* ugly. :-)
Heartily agree. I would even go one step further and say 'use a factory
registry'. We have a generic for it, and it works like a top:
const
MARSHAL_HEC = 'hec_marshaller';
CODE_PAGE = 'code_page';
MarshallingRegistry.AddFactory(
MARSHAL_HEC,THecMarshallerFactory.Create);
...
Kind := MARSHAL_HEC;
Configuration := TConfiguration.Create;
Configuration.Add(CODE_PAGE,CODE_PAGE_SPANISH);
Marshaller := MarshallingRegistry.Build(Kind,Configuration);
Quote
Cheers,
Jarle
Likewise :)
-- Ritchie Annand
Senior Software Architect
www.malibugroup.com
nimble.nimblebrain.net
wiki.nimblebrain.net