Factory class
KeepYourMind
vyacheslav at blue-code.org
Thu Mar 19 08:49:42 PDT 2009
Hello. I'm try to write factory class but have some problems.
Source example:
// Pizza interface
interface IPizza
{
void doSome();
}
// Pizza
class IMPizza : IPizza
{
void doSome() {}
}
// try to raise functinally
class CoolPizza : IPizza
{
void doSome() {}
void doSomeA() {}
}
// Factory
static class PizzaFactory
{
static IPizza factory(char[] name)
{
switch (name) {
case "im":
return new IMPizza;
break;
case "cool":
return new CoolPizza;
break;
default:
throw new Exception("incorrect pizza name");
break;
}
}
}
// run
void main()
{
auto pizza = PizzaFactory.factory();
pizza.doSome(); // OK
pizza.doSomeA(); // error: IPizza.doSomeA() not found
}
What i need to do for pizza.doSomeA() begin work?
More information about the Digitalmars-d-learn
mailing list