Week 5 Flashcards
1
Q
Creational design patterns - Singleton
A
- Intent:
- Ensure that only one instance of a class is created.
- Provide a global point of access to the object.
- Implementation
- Example
- To instantiate a Logger for logging purpose
- To have a centralized configuration for the entire application
2
Q
Creational design patterns - Factory
A
- Intent:
- creates objects without exposing the instantiation logic to the client.
- refers to the newly created object through a common interface
- Implementation
3
Q
Structural design patterns – Façade
A
- Intent:
- To make a complex subsystem easier to use, a simple interface should be provided for a set of interfaces in the subsystem.
- The dependencies on a subsystem should be minimized.
- Implementation: define a Facade object that
- implements a simple interface in terms of (by delegating to) the interfaces in the subsystem and
- may perform additional functionality before/after forwarding a request.
- Example
- a simple interface is required to access a complex system.
- an entry point is needed to each level of layered software
4
Q
Structural design patterns - Proxy
A
- Intent:
- To provide a “Placeholder” for an object to control references to it.
- Implementation:
- Example
Consider an image viewer program that lists and displays high resolution photos. The program has to show a list of all photos however it does not need to display the actual photo until the user selects an image item from a list.
5
Q
Structural design patterns - Adapter
A
Structural design patterns - Adapter
- Intent:
- Convert the interface of a class into another interface clients expect.
- Adapter lets classes work together, that could not otherwise because of incompatible interfaces.
- Implementation:
- Example
- Wrappers used to adopt 3rd parties libraries and frameworks - most of the applications using third party libraries use adapters as a middle layer between the application and the 3rd party library to decouple the application from the library. If another library has to be used only an adapter for the new library is required without having to change the application code..
6
Q
Behavioral design patterns - Observer
A
- Intent:
- Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically..
- Example
- Lets’ take the example of a news agency. A news agency gather news news and publish them to different subscribers. We need to create a framework for and agency to be able to inform immediately, when event occurs, its subscribers about the event. The subscribers can receive the news in different ways: Emails, SMS, … The solution need to be extensively enough to support new types of subscribers(maybe new communication technologies will appear)