[fpc-pascal] Implementing Factory Method with Pascal
Juha Manninen
juha.manninen62 at gmail.com
Sat Nov 28 12:11:50 CET 2015
On Sat, Nov 28, 2015 at 1:48 AM, Marcos Douglas <md at delfire.net> wrote:
> Another tip: Factories resolve some problems but there is a cost. The
> factory will creates your instance (object) but it know only one
> constructor, ie, the base class constructor.
No, the constructor must then be virtual.
Inheritance is OK if all public virtual methods can be defined in an
abstract base class. If works as an interface then (without
"interface" keyword).
It does not work when you need TDog.Bark but it would work with
abstract function TAnimal.Says: String, which is implemented as "
Return 'wuff' " for TDoc and " Return 'miou' " for TCat.
But yes, the other answers are better for more complex cases.
Juha
More information about the fpc-pascal
mailing list