[fpc-pascal] Adding method dynamically to a class

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Jun 20 10:39:32 CEST 2012

On Wed, 20 Jun 2012, ik wrote:

> On Wed, Jun 20, 2012 at 10:20 AM, <michael.vancanneyt at wisa.be> wrote:
>> On Wed, 20 Jun 2012, ik wrote:
>>  On Wed, Jun 20, 2012 at 8:33 AM, LacaK <lacak at zoznam.sk> wrote:
>>>  **
>>>> Class helpers would not help ?
>>>> http://wiki.freepascal.org/**Helper_types<http://wiki.freepascal.org/Helper_types>
>>> They can, but there is a protocol that I'm trying to create that provides
>>> me information what to execute (out of white list). The thing is, that the
>>> first request maps the methods to be used, and there could be 2 or 200. To
>>> implement 200 methods that might be used is not a good idea imho, but
>>> adding the proper method to the instance/class will work much better.
>> I don't understand this argument. The available methods must have an
>> implementation somewhere anyway. That means your code does not get smaller
>> by adding them dynamically.  Somewhere you must choose which method to
>> execute, and whether it is allowed or not, so this logic must be present
>> also. None of this requires dynamically adding methods as
>> far as I can see, or is made easier by dynamically adding methods.
>> So finally, what is gained by adding them dynamically ? Or what forces you
>> to even consider this path ?
> Think of a plug-able system.  I have an engine, and code to execute.
> Instead of compile everything to an ELF/PE, I place code on dynamic shard
> library, and load it on run time when needed.
> The idea is that the engine will not be rewritten for every new request
> (that comes often), because it's logic (almost) never changes, but to load
> code on demand that often changes, provide additional functions, changes of
> logic, bug fixes etc...
> The idea of implementing it like so, came to me after few years now of
> having the need to recreate the whole logic based of the code for every new
> demand from the client (both as human, and as software). The main code
> almost never changes, but so many additions, that I'm starting to use the
> dynamic execution of methods, and now I realize, that if I'll extract it to
> a shard library, it will be much easier to change, add etc... only the
> actual need, and not to touch other stuff, and that requires me to design
> an engine instead.

This is understandable, but none of this explains why you would need to add 
a method to a class ? I have a similar system, but do not need to add
methods to a class ?


More information about the fpc-pascal mailing list