TDeriver - Polymorphic Creation of Instances.
=============================================

Consider  the usual example about polymorphism.   Suppose TBase is a base class
and  TDerived1 and is derived from it.  If they provide a method Plot that plot
them (whatever it means)  and you want  to plot an  instance I of  them all you
have to do is:

	I.Plot;

Even if an other class  TDerived2  is  derived,  the  previous  code  needs  no
modification.  Very nice indeed!

Unfortunately somewhere  you have to create  I.  There the  class of I matters!
Normally case-s or sequences of if are used.

	if <some set of conditions> then
		I := TBase.Create(...)
    else if <some other set of conditions> then
		I := TDerived1.Create(...);

That's  ugly!  Moreover, and  worse, if another class  TDerived2 is derived you
have  to go back where the creation of I is and update the code.  There must be
a better way!

Now,  our C++ friends devised something and,  as everything (useful) you can do
in C++ you can do better in Delphi, here it is "Polymorphic Creation".  Add the
Deriver unit to your project  and some  line of  code to  your classes  and the
creation of I becomes:

   I := TBase.DerivedClass(<conditions>).Create(...);

Moreover, if  another class TDerived2  is derived...nothing happens.   The same
code  holds.   Moreover, if  after 12  derivations you  discover you  need more
conditions  to discriminate the  new class and  create it, well,  the same code
still holds (of course you have to modify something to obtain the new condition
but no modification is required to old classes nor to the creation code).

USAGE
=====

The  project _cmptst contains the unit Deriver that defines the TDeriver class.
Other units are an example of use.    Compile  the  project  and  run  it  with
different  command line parameters starting from 0.  The add the Derived2 unit,
recompile and runt it again.

_cmptst is a Delphi 1 project. The porting to Delphi 2 is straightforward. Some
semplification can be obtained using the finalization clause that does not exist
in Delphi 1.

CONTENTS
========

readme.txt - this file
deriver\DERIVER.PAS - TDeriver class
base\BASE.PAS - TBase, a sample base class
derived1\DERIVED1.PAS - TDerived1, a sample derived class
derived2\DERIVED2.PAS - TDerived2, a second sample derived class
main\MAIN.* - the main form, contains creation code
_dcu\*.DCU - compiled units
_CMPTST.* - sample project files

 
LEGALITIES
==========

----------- 
 Copyright 
----------- 
Permission  to use, copy and distribute this software and its documentation for
any purpose and without  fee  is  hereby  granted,  provided  that  it  is  not
modified.

THIS  SOFTWARE  IS  PROVIDED  "AS  IS"  AND  WITHOUT  ANY  EXPRESS  OR  IMPLIED
WARRANTIES, INCLUDING,  WITHOUT   LIMITATION,   THE   IMPLIED   WARRANTIES   OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.


If  you find it useful  then I would appreciate  any Comments, Suggestions, Bug
finds etc.  and if you improve something, please send me a copy of the changes.

This  is quite advanced  object and Delphi  programming.  Therefore,  I am very
sorry but I do not want receive messages starting with "I am new to Delphi...".
Write to me if you have found a problem, not if you have a problem which can be
answered by posting to some Delphi newsgroup.


Mauro Venturini
E-mail: mpv@acm.org
