Week 5 - Factory Method Flashcards

1
Q

What does the factory method design pattern do?

A

It is a design pattern for ‘manufacturing’ objects. It allows a program to work with instances of concrete classes of an interface when the program cannot anticipate which class it is working with.

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

What us the intent of the factory method?

A

To define an interface for creating an object, but to let the subclasses decide which class to instantiate.

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

What is the motivation of factory method?

A

When an application uses a number fo different types of an object - it knows when to create an object but not what specific subtype of that classes to create because it is independent from the object (i.e. It only knows about interfaces).

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

What is the Applicability of the factory method?

A

Used when a class can’t anticipate which specific type of object to create.

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

How do you implement the factory method?

A

It is a method/function in the concrete creator class. This method is not called factory method in the implementation, but rather something else appropriate to the program. When it is called, it returns an instance of a particular concrete product class that implements the product interface. The main creator class relies on subclasses of it to define the particular factory methods, each one returning a different product class type that is appropriate for that creator.

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

When is the factory method used?

A

It is almost always used when interfaces are involved. It is used to create and instance of the concrete abject that implements the interface.

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

Give some examples of factory method in JHD?

A

Creating the Drawing in DrawApplication
Creating Handles in Figure
Creating Figures in CreationTool
Creating different tools for dragging shapes, dragging handles, dragging an ‘area tracker’ within SelectionTool

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

What are the disadvantages of the factory method?

A

Clients might have to create an new subclass of the creator class whenever they create a new concreteProduct class.

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

What are the advantages of factory method?

A

Provides hooks for subclasses.

Eliminates the need to bind static classes into code, allowing for more flexibility.

It works with parallel class hierarchies, by defining the connection between these hierarchies and knows what classes belong together.

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

What are hooks in classes?

A

A point in a class that is flexible and allows the future extension of the class in its subclasses. The hook will have sensible default behaviour which is overwritten to extend the class via its subclass.

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

What is a a parallel hierarchiy?

A

A hierarchy structure that has two trees of class hierarchies that are connected at the top. Each class in the hierarchies matches a similar class in the other hierarchy.

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

What are issues with implementing factory method?

A

The creator might be abstract and not provide an implementation of the factory method it declares. Thus implementation needs to be defined in the subclasses.

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

What is a parameterised factory method?

A

A factory method that takes parameters and creates and return a different kind of product depending on the parameters. It is very flexible in that one factory method could create all product classes as long as the correct parameter is supplied.

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