Possible Duplicate:
Interface vs Abstract Class (general OO)
Hi Experts,
I am reading on Factory patterns
We define interface, interface is implemented by classes. Based on certain attribute we decide which class is instantiated
We define abstract class and implement it in the subclasses.
Both the examples listed are quite different. Based on fundamentals that I remember.
Help me understand how both using interaces vs using abstract classes is called as factory pattern ?
Are these two valid approaches ?
Apologies for formatting issues.
Thanks in advance
Since patterns are abstract concepts, they are not strictly dependent on implementations; so using interfaces or abstract classes are both valid approaches imo.
The main idea of Factory pattern is to "simplify" object creation by making an abstraction.
Whether you use interfaces or abstract classes depends on your implementation. In my experience, factory pattern usually came to play when the class structure is already defined. For example, I've already made the decision to use interfaces or abstract classes in my model and now I want to refactor so that object creation is simpler => I go for the factory pattern. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With