Abstract factory Flashcards
(39 cards)
What is the main purpose of the Abstract Factory Pattern?
To create families of related objects without specifying concrete classes.
How does the Abstract Factory Pattern differ from the Factory Method Pattern?
Factory Method creates one product, while Abstract Factory creates multiple related products.
Why is the Abstract Factory Pattern classified as a creational design pattern?
Because it focuses on object creation in a structured and flexible way.
What problem does the Abstract Factory Pattern solve in software design?
It ensures consistency among related objects and hides object creation from the client.
How does the Abstract Factory Pattern promote loose coupling?
: It abstracts object creation, allowing the client to work with interfaces instead of concrete classes.
What is the key advantage of using an Abstract Factory over directly instantiating objects?
It provides consistent object creation and makes it easier to switch product families.
What is meant by the term “family of related objects” in the Abstract Factory Pattern?
A group of products that are designed to work together, like UI elements in a theme.
What would happen if an Abstract Factory did not enforce consistency across related products?
Incompatible objects might be used together, causing runtime errors or UI inconsistencies.
How does the Abstract Factory Pattern help maintain the Open-Closed Principle?
New product families can be added without modifying existing client code.
When should you use the Abstract Factory Pattern instead of the Factory Method Pattern?
When you need to create multiple related objects instead of just one.
What are the main components of the Abstract Factory Pattern?
Abstract Factory, Concrete Factory, Abstract Product, Concrete Product, Client.
What role does the Abstract Factory play in the pattern?
It defines interfaces for creating families of related products.
What role do the Concrete Factories play in the pattern?
They implement the Abstract Factory and create specific product families.
What is an Abstract Product in the Abstract Factory Pattern?
It defines a common interface for a family of products.
How do Concrete Products differ from Abstract Products?
They provide specific implementations of abstract products.
How does the Abstract Factory ensure that all created objects belong to the same family?
Each Concrete Factory creates only products from the same family.
How does polymorphism play a role in the Abstract Factory Pattern?
The client interacts with abstract products, while factories return concrete implementations.
Why does the Abstract Factory Pattern typically involve interfaces or abstract classes?
To ensure flexibility and enforce consistency across product families.
What happens if a client code directly instantiates product classes instead of using an Abstract Factory?
It violates encapsulation, making it harder to switch product families.
What is the difference between an Abstract Factory and a Simple Factory?
Abstract Factory creates multiple related products, while Simple Factory creates only one type of product.
How would you apply the Abstract Factory Pattern in a UI framework that supports different themes?
Create factories for each theme (e.g., DarkThemeFactory, LightThemeFactory) to produce UI elements.
How would the Abstract Factory Pattern help in a game with different types of worlds (e.g., Medieval, Sci-Fi, Fantasy)?
Each world would have a factory to create world-specific objects (e.g., characters, environments).
How does the Abstract Factory Pattern improve database connection handling when working with multiple databases?
It provides a factory for each database type (e.g., MySQLFactory, PostgreSQLFactory).
How would the Abstract Factory Pattern be useful in designing a cross-platform application?
Each platform (Windows, macOS, Linux) would have its own factory to create platform-specific components.