Factory class

Simen Kjaeraas simen.kjaras at gmail.com
Thu Mar 19 12:58:02 PDT 2009


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( );
    }
}


More information about the Digitalmars-d-learn mailing list