Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-29 Thread Michael Van Canneyt
On Sun, 29 Nov 2015, Marcos Douglas wrote: On Sat, Nov 28, 2015 at 5:34 PM, Michael Van Canneyt wrote: !! OMG !! Maybe we just discovered a new form of multiple inheritance... Definite proof we should all use C++, or maybe it is time for C+++ !! You have humor,

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-29 Thread Marcos Douglas
On Sun, Nov 29, 2015 at 6:17 AM, Michael Van Canneyt wrote: >> > First of all, inheritance is inherent in object oriented programming, since > every object descends from a base object. > So saying that 'inheritance must die' is a stupid sentence or title for a > blog. Now

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Marcos Douglas
On Sat, Nov 28, 2015 at 9:11 AM, Juha Manninen wrote: > On Sat, Nov 28, 2015 at 1:48 AM, Marcos Douglas wrote: >> Another tip: Factories resolve some problems but there is a cost. The >> factory will creates your instance (object) but it know only one

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Graeme Geldenhuys
Hi Marcos, On 2015-11-27 23:48, Marcos Douglas wrote: > Why do you have a factory to create different types of animals > (classes)? Doesn't make sense. Maybe in Luciano's simple example a factory is not the best use case, but the Simple Factory design pattern can be very useful in other cases.

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Serguei TARASSOV
Hello, What is an explanation why the first code is not good but the second one is good? At least, the first code is three times as shorter and clear. Second code seems to be taken from Delphi 7 where the first one doesn't works. On 28/11/2015 12:00, fpc-pascal-requ...@lists.freepascal.org

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Marcos Douglas
On Sat, Nov 28, 2015 at 7:32 AM, Graeme Geldenhuys wrote: > > Maybe in Luciano's simple example a factory is not the best use case, > but the Simple Factory design pattern can be very useful in other cases. I agree in both affirmations. But as I said before,

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Graeme Geldenhuys
Hi Anthony, On 2015-11-28 00:16, Anthony Walter wrote: > type > IBarkable = interface(IInterface) > ['{B241068F-2ED9-43C7-066B-778B94CB58F9}'] > procedure Bark; > end; > ...snip... That is a much better solution for what Luciano wants to accomplish. > and later ... > > if Animal is

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Juha Manninen
On Sat, Nov 28, 2015 at 1:48 AM, Marcos Douglas 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

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Marco van de Voort
In our previous episode, Marcos Douglas said: > > Inheritance breaks encapsulation. This was written even in GoF Patterns. > There are many post, on the web, explaining why inheritance is evil. > I searched on Google right now: >

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Juha Manninen
On Sat, Nov 28, 2015 at 2:07 PM, Marcos Douglas wrote: > Even using virtual constructors, the factory will know only one > signature to instantiate objects. Yes and often that is enough. A constructor is then part of the API. (Lets call it API now to avoid confusion with the

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Michael Van Canneyt
On Sat, 28 Nov 2015, Marcos Douglas wrote: Inheritance breaks encapsulation. This was written even in GoF Patterns. There are many post, on the web, explaining why inheritance is evil. I searched on Google right now:

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Graeme Geldenhuys
On 2015-11-28 19:34, Michael Van Canneyt wrote: > !! OMG !! Maybe we just discovered a new form of multiple inheritance... > Definite proof we should all use C++, or maybe it is time for C+++ !! ROFL - you just made my day. :-) > There is no golden rule which encapsulates (sic) all situations.

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Marcos Douglas
On Sat, Nov 28, 2015 at 3:31 PM, Marco van de Voort wrote: > In our previous episode, Marcos Douglas said: >> >> Inheritance breaks encapsulation. This was written even in GoF Patterns. >> There are many post, on the web, explaining why inheritance is evil. >> I searched on

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Marcos Douglas
On Sat, Nov 28, 2015 at 5:34 PM, Michael Van Canneyt wrote: > > !! OMG !! Maybe we just discovered a new form of multiple inheritance... > Definite proof we should all use C++, or maybe it is time for C+++ !! You have humor, very funny. [clap clap clap] > Please... > >

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread patspiper
On 27/11/15 23:21, luciano de souza wrote: ... But, if this not works, how to implement the Factory Method in Freepascal? What about: var animal: TDog; BEGIN animal := TAnimalFactory.create(atDog); try if animal is TDog then TDog(animal).bark; finally animal.free; end;

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-28 Thread Inoussa OUEDRAOGO
> There is no golden rule which encapsulates (sic) all situations. +1 > People should use their brain and choose a pattern or methodology > judiciously, +1, after all that is what engineering is all about. -- Inoussa O. ___ fpc-pascal maillist -

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Marcos Douglas
On Fri, Nov 27, 2015 at 7:44 PM, luciano de souza wrote: > If I need to do "TAnimalFactory.create(atDog) as Tdog", perhaps, it > would be better not to use a factory, doing simply "TDog.create". You're right, use simply TDog.Create. Why do you have a factory to create

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Marcos Douglas
On Fri, Nov 27, 2015 at 10:15 PM, luciano de souza wrote: > If I want to change the type of the instance, better is to use > generics. A factory is only a batch builder of the same objects. OK, but you don't need generics either ;) Marcos Douglas

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Marcos Douglas
On Fri, Nov 27, 2015 at 10:16 PM, Anthony Walter wrote: > if Animal is IBarkable then (Animal as IBarkable).Bark; Your approach is much better, but don't use casting is even better when we working with a true object oriented, because casting is a "procedural command" for the

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Mattias Gaertner
One solution: var animal: TDog; BEGIN animal := TAnimalFactory.create(atDog) as TDog; try animal.bark; finally animal.free; end; END. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Graeme Geldenhuys
On 2015-11-27 21:21, luciano de souza wrote: > I'd like to understand how to implement the Factory Method pattern in Pascal. See my "Simple Factory Pattern" article. I've written about many other design patterns too. http://geldenhuys.co.uk/articles/ Regards, - Graeme - -- fpGUI Toolkit

[fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread luciano de souza
Hello all, I'd like to understand how to implement the Factory Method pattern in Pascal. In my example, there are four classes: 1. TAnimal - The parent and abstract class; 2. TDog and TCat - The specialized classes; 3. TAnimalFactory - The class which creates instances of animals, having

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread luciano de souza
Marcos, Your answer and the excelent article of Graeme clarify the question. If I want to change the type of the instance, better is to use generics. A factory is only a batch builder of the same objects. Graeme, your article opened my mind. The mappings and the registers caused me a very

Re: [fpc-pascal] Implementing Factory Method with Pascal

2015-11-27 Thread Anthony Walter
type IBarkable = interface(IInterface) ['{B241068F-2ED9-43C7-066B-778B94CB58F9}'] procedure Bark; end; TAnimal = class(IInterface) end; TDog = class(TAnimal, IBarkable) public procedure Live; override; procedure Bark; end; and later ... if Animal is IBarkable then