Midterm Review 2 Flashcards

1
Q

What is the Builder pattern?

A

An object creational pattern that separates the construction of a complex object from its representation so that the same construction process can create different representations.

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

What is the motivation for the Builder pattern?

A

It is useful when given data can have multiple complex representations and when similar types of objects can have vastly different construction processes

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

When should you use the Builder pattern?

A

When the algorithm for creating a complex object should be independent of the parts that make up the object and how they are assembled; When the construction process must allow different representations for the object that’s constructed

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

What are the participants of the Builder pattern?

A
  • Builder: Specifies the abstract methods for building each part of the object
  • ConcreteBuilder: Handles the construction of the individual parts of each object implementation, maintains a representation of the object as it is constructed and returns the newly created object
  • Director: Accepts a builder and uses it to construct an object
  • Product: Represents the constructed object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the pros and cons of the Builder pattern?

A

Pros: allows you to vary your products’ internal representation and hides how assembly actually takes place, isolates code construction and representation, offers finer control over construction process

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

What is the Composite pattern?

A

An object structural pattern which composes objects into tree structures to represent part-whole hierarchies and lets clients treat individual objects as compositions of objects uniformly.

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

What is the motivation for the Composite pattern?

A

Using a composite, graphics components can be handled interchangeably whether they are the final graphic being drawn, or if they are a parent component that comprises further graphics

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

When should you use the Composite pattern?

A

When you want to represent part-whole hierarchies of objects or when you want clients to be able to ignore the difference between compositions of individual objects (clients will treat all objects in the composite structure uniformly)

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

What are the participants of the Composite pattern?

A
  • Component: Declares the interface for objects in the composition, implements the default behaviour for the interface common to all
    classes, as appropriate, and declares an interface for accessing and managing its child components
  • Leaf: Represents leaf objects in the composition (a leaf has no children), defines behaviour for primitive objects in the composition
  • Composite: Defines behavior for components that have children, stores child components, and implements child-related operations in the Component interface
  • Client: Manipulates objects in the composition through the Component
    interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the pros and cons of the Composite pattern?

A

Pros: defines class hierarchies consisting of primitive objects and composite objects, makes the client simple, makes it easier to add new kinds of components
Cons: can make your design overly general

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

What is the Adapter pattern?

A

A class/object structural pattern which converts the interface of a class into another interface clients expect and lets classes work together that couldn’t otherwise because of inoperable interfaces.

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