Lecture 10-11 Flashcards

1
Q

Where did design patterns originate from?

A

Design patterns originated from recurring themes in planning and building architecture.

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

What is a creational pattern in design patterns?

A

A pattern that deals with object creation mechanisms.

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

What is the Singleton pattern?

A

A creational pattern that ensures a class has only one instance and provides a global point of access to that instance.

Example: We want only one instance of a class (such as a Scanner or Logger class)

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

What is the purpose of the Singleton pattern?

A

To ensure a class only has one instance for the duration of the system.

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

What is an example of a problem that the Singleton pattern solves?

A

Ensuring there is only one instance of a Scanner or Logger class.

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

What is the Factory Method pattern?

A

A creational pattern that defines an interface for creating an object, but lets subclasses decide which class to instantiate.

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

What is an example application of the Factory Method pattern?

A

A superclass Animal with a makeNoise() method, and subclasses like Cow, Dog, and Cat that implement the makeNoise() method differently.

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

What are structural patterns concerned with?

A

How classes and objects can be composed to form larger structures.

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

What do structural patterns focus on?

A

How classes inherit from each other and how they are composed from other classes.

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

What is the Adapter pattern?

A

A structural pattern that allows incompatible interfaces to work together without modifying their existing code.

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

What is an example of the Adapter pattern?

A

Two F1 temperature sensors with incompatible temp-reporting methods, or the travel electricity socket problem with Euro and Australian socket plugs.

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

What is the intent of the Adapter pattern?

A

To convert the interface of a class into another interface that the client expects.

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

What is the Composite pattern?

A

A structural pattern that composes objects into tree structures to represent whole-part hierarchies.

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

What is the applicability of the Composite pattern?

A

When you want to represent whole-part hierarchies of objects.

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

What is the Observer pattern?

A

A behavioral pattern where when a particular object in the system changes its state, other ‘subscribed’ objects are notified and updated automatically.

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

What is the intent of the Observer pattern?

A

To define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

17
Q

When should the Observer pattern be used?

A

When a change to one object requires changing others, or when an object should be able to notify other objects without making assumptions about those objects.

18
Q

What problem does the Singleton pattern commonly solve?

A

Ensuring only one instance of a class, such as a Scanner or Logger class, is created.

19
Q

What must be true for a class to use the Singleton pattern?

A

There must be exactly one instance of the class, and it must be accessible from a well-known access point.

20
Q

What does the Factory Method pattern allow subclasses to do?

A

Decide which class to instantiate when creating an object.

21
Q

What are the 3 categories of Design Patterns

A
  1. Creational Pattern
  2. Structural Pattern
  3. Behavioural Pattern
22
Q

Give 2 examples of a Structural Pattern

A
  1. Adapter Pattern
  2. Composite Pattern
23
Q

Give 2 examples of a Creational Pattern

A
  1. Singleton
  2. Factory Method
24
Q

Give 2 examples of a Behavioural Pattern

A
  1. Observer Pattern
  2. Strategy Pattern