I was reading design patterns from a website
There I read about Factory, Factory method and Abstract factory but they are so confusing, am not clear on the definition. According to definitions
Factory – Creates objects without exposing the instantiation logic to the client and Refers to the newly created object through a common interface. Is a simplified version of Factory Method
Factory Method – Defines an interface for creating objects, but let subclasses to decide which class to instantiate and Refers to the newly created object through a common interface.
Abstract Factory – Offers the interface for creating a family of related objects, without explicitly specifying their classes.
I also looked the other stackoverflow threads regarding Abstract Factory vs Factory Method but the UML diagrams drawn there make my understanding even worse.
Can anyone please tell me
- How are these three patterns different from each other?
- When to use which?
- And also if possible, any java examples related to these patterns?