Sof Dev - Design Patterns Flashcards
What is the Factory Pattern?
A creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created.
What are design patterns?
Design Patterns are meant to provide a general reusable solution to one type of problem during software development.
What are the four parts of the Factory Pattern?
Product Interface: Declares the interface for the product created by the factory.
Concrete Products: The actual objects that implement the product interface.
Creator Class: Declares the factory method that returns an instance of the product interface. It may also contain additional business logic.
Concrete Creator Subclasses:
Implement the factory method to create specific instances of the concrete products, thus defining the type of objects the factory will produce.
What is the abstract factory pattern?
Abstract Factory is a creational design pattern that lets you produce families of related objects without specifying their concrete classes.
What are the five parts of the abstract factory pattern?
Abstract Factory Interface:
Declares the interface for creating product objects.
Concrete Factories:
Implement the Abstract Factory interface to produce families of related products.
Abstract Product Interface:
Declares the interface for a type of product object.
Concrete Products:
Implement the Abstract Product interface, representing specific product variants.
Client:
Uses the Abstract Factory and Abstract Product interfaces to interact with families of related products without being aware of their concrete classes.
Factory Pattern vs Abstract Factory Pattern
While the Factory Pattern uses inheritance and gives a complete object in one go, the Abstract Factory Pattern uses composition and returns a family of related classes.