Factory class
KeepYourMind
vyacheslav at blue-code.org
Fri Mar 20 00:49:54 PDT 2009
Denis Koroskin Wrote:
> 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();
> }
>
Got it. If use one from this ways i'm not need factory, only switch. Bad. :-(
More information about the Digitalmars-d-learn
mailing list