rg20
asked on
Factory Design pattern
To all,
I understand the benefits of a factory design if client is not supposed to know what concrete class to create, but something like this confuses me
Factory factory = new ConcreteFactory2();//Decid es which object must create.
Base obj = factory.GetObject();
If this is in the main class, then why not just say
ConcreteFactory2 factory = new ConcreteFactory2()
I could understand Factory factory = new Factory(2)
where the 2 would represent the object to return.
My question:
Is there a real purpose for having this Factory factory = new ConcreteFactory2();//Decid es which object must create as the programmer needs to know which to instanciate?
Also looking at this from a factory prosepctive, I would like to hear from anyone who believes that is is better to use Abstract classes instead of interfaces. I understand that interfaces cannot pass private variables through, but I don't really need to do that.
Thanks
I understand the benefits of a factory design if client is not supposed to know what concrete class to create, but something like this confuses me
Factory factory = new ConcreteFactory2();//Decid
Base obj = factory.GetObject();
If this is in the main class, then why not just say
ConcreteFactory2 factory = new ConcreteFactory2()
I could understand Factory factory = new Factory(2)
where the 2 would represent the object to return.
My question:
Is there a real purpose for having this Factory factory = new ConcreteFactory2();//Decid
Also looking at this from a factory prosepctive, I would like to hear from anyone who believes that is is better to use Abstract classes instead of interfaces. I understand that interfaces cannot pass private variables through, but I don't really need to do that.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the input.