Lecture 10-11 Flashcards
Where did design patterns originate from?
Design patterns originated from recurring themes in planning and building architecture.
What is a creational pattern in design patterns?
A pattern that deals with object creation mechanisms.
What is the Singleton pattern?
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)
What is the purpose of the Singleton pattern?
To ensure a class only has one instance for the duration of the system.
What is an example of a problem that the Singleton pattern solves?
Ensuring there is only one instance of a Scanner or Logger class.
What is the Factory Method pattern?
A creational pattern that defines an interface for creating an object, but lets subclasses decide which class to instantiate.
What is an example application of the Factory Method pattern?
A superclass Animal with a makeNoise() method, and subclasses like Cow, Dog, and Cat that implement the makeNoise() method differently.
What are structural patterns concerned with?
How classes and objects can be composed to form larger structures.
What do structural patterns focus on?
How classes inherit from each other and how they are composed from other classes.
What is the Adapter pattern?
A structural pattern that allows incompatible interfaces to work together without modifying their existing code.
What is an example of the Adapter pattern?
Two F1 temperature sensors with incompatible temp-reporting methods, or the travel electricity socket problem with Euro and Australian socket plugs.
What is the intent of the Adapter pattern?
To convert the interface of a class into another interface that the client expects.
What is the Composite pattern?
A structural pattern that composes objects into tree structures to represent whole-part hierarchies.
What is the applicability of the Composite pattern?
When you want to represent whole-part hierarchies of objects.
What is the Observer pattern?
A behavioral pattern where when a particular object in the system changes its state, other ‘subscribed’ objects are notified and updated automatically.