[fpc-pascal] Implementing Factory Method with Pascal

Serguei TARASSOV serge at arbinada.com
Sat Nov 28 14:09:11 CET 2015


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 

On 28/11/2015 12:00, fpc-pascal-request at lists.freepascal.org wrote:
>> >if Animal is IBarkable then (Animal as IBarkable).Bark;
> This is not good usage of Interfaces. Use the interface variable instead.
> var
>    intf: IBarkable
> begin
>    if Supports(Animal, IBarbable, intf) then
>    begin
>      intf.Bark;
>      // you can continue here using intf further without casting
>    end;

More information about the fpc-pascal mailing list