Factory class
Denis Koroskin
2korden at gmail.com
Thu Mar 19 14:41:37 PDT 2009
On Thu, 19 Mar 2009 22:58:02 +0300, Simen Kjaeraas <simen.kjaras at gmail.com> wrote:
> On Thu, 19 Mar 2009 18:06:37 +0100, KeepYourMind
> <vyacheslav at blue-code.org> wrote:
>
>> Sean Kelly Wrote:
>>
>>> KeepYourMind wrote:
>>> >
>>> > What i need to do for pizza.doSomeA() begin work?
>>>
>>> cast pizza to CoolPizza.
>>
>> Problem is i dont know what class returned. "char[] name" is dynamic
>> and getting from command-line arguments.
>
> Then you need some test to see if it really is a CoolPizza.
>
> void main( string[] args ) {
> auto pizza = PizzaFactory.factory( args[1] );
> pizza.doSome( );
> if ( args[1] == "CoolPizza" ) {
> ( cast( CoolPizza ) pizza ).doSomeA( );
> }
> }
Not like that. Here is a better way:
auto pizza = PizzaFactory.factory( name );
pizza.doSome();
if (auto cool = cast(CoolPizza)pizza) {
cool.doSomeA();
}
More information about the Digitalmars-d-learn
mailing list