ABSTRACT FACTORY Flashcards

1
Q

Abstract Factory is

A

a creational design pattern that lets you
produce families of related objects without specifying their
concrete classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Abstract Products declare

A

interfaces for a set of distinct but
related products which make up a product family.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Concrete Products

A

are various implementations of abstract
products, grouped by variants. Each abstract product (chair/
sofa) must be implemented in all given variants (Victorian/
Modern).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The Abstract Factory interface

A

declares a set of methods for
creating each of the abstract products.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Concrete Factories implement

A

creation methods of the
abstract factory. Each concrete factory corresponds to a specific variant of products and creates only those product variants.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When should you use the Abstract Factory?

A

When your code needs to work with various families of related products, but you don’t want it to depend on the concrete classes of those products, as they might be unknown beforehand or to allow for future extensibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the Abstract Factory provide?

A

An interface for creating objects from each class of the product family.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why does using the Abstract Factory help avoid mistakes in object creation?

A

Because by creating objects through the Abstract Factory interface, you eliminate the risk of creating the wrong variant of a product that doesn’t match the products already created by your app.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When should you consider implementing the Abstract Factory?

A

When you have a class with a set of Factory Methods that blur its primary responsibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does the Abstract Factory relate to well-designed programs?

A

In well-designed programs, each class is responsible for only one thing. If a class handles multiple product types, it might be worth extracting its factory methods into a standalone factory class or a full-blown Abstract Factory implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the first step in implementing an Abstract Factory?

A

Map out a matrix of distinct product types versus variants of these products.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What should you declare for all product types?

A

Declare abstract product interfaces for all product types and ensure all concrete product classes implement these interfaces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the abstract factory interface include?

A

A set of creation methods for all abstract products.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How are concrete factories implemented?

A

Implement a set of concrete factory classes, one for each product variant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where should the factory initialization code reside?

A

Somewhere in the app, depending on the configuration or environment. It should instantiate a specific concrete factory class and pass it to all classes that construct products.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What should you replace direct product constructor calls with?

A

Replace them with calls to the appropriate creation method on the factory object.

17
Q

What are the benefits of using an Abstract Factory?

A
  1. Ensures product compatibility.
  2. Avoids tight coupling between concrete products and client code.
  3. Adheres to the Single Responsibility Principle by centralizing product creation code.
  4. Follows the Open/Closed Principle, allowing new product variants without breaking existing code.
18
Q

What is a drawback of the Abstract Factory pattern?

A

The code can become overly complicated due to the introduction of many new interfaces and classes.

19
Q

How does the Abstract Factory relate to the Factory Method?

A

Many designs start with the Factory Method for simplicity and evolve into Abstract Factory, Prototype, or Builder for greater flexibility.

20
Q

What is the difference between Abstract Factory and Builder?

A

Builder constructs complex objects step by step.
Abstract Factory specializes in creating families of related objects and returns the product immediately.

21
Q

How can Abstract Factory and Bridge work together?

A

Abstract Factory can encapsulate relations and hide complexity when some abstractions defined by Bridge require specific implementations.

22
Q

Can Abstract Factory, Builder, and Prototype be implemented as Singletons?

A

Yes, all three can be implemented as Singletons.