Lecture 6: Design Patterns Flashcards
What is a design pattern?
Design pattern is a repeatable solution to a commonly occurring problem in software design which can be used in many different situations.
“Abstracts a recurring solution from a common problem in software design”
What does it improve?
documentation and maintenance
When solving the designs, what does it do?
- More flexible
- Elegant
- Reusable
What does a design class contain?
- Dependencies
- Structures
- Interactions
- Conventions
What are the four elements that must be condsidered?
- Name
- Problem
- Solution
- Consequences and trade-offs application
4 Goals
- Arrange good design
- Good design structures and explicit names
- Capture and preserve design information
- Facilitate restructuring/refactoring
What are the benefits of patterns?
- Design reuse
- Uniform design vocabulary
- Enhance understanding, restructuring and team communication
- Basics of automation
- Abstracts from unimportant details
What is design pattern classification?
Design patterns level in their quantity and level of **abstraction **
What is the purpose?
**Creational: **Process of object creation
Hides how instances are created
Separates the system from object creation
Structural: The composition of classes or objects
Behavioural: Characterise the ways in which classes or objects interact and distribute responsibilities
Complete the Creational, Structural and Behavioural table
What is a behavioural relationship?
- The design pattern is about the class’s objects communication
- Most concerned with communication between objects
What is an observer?
Defines one-to-many dependency between objects so that when one object changes state, all dependants are notified and updated
What is strategy?
Defines a family of algorithms, Encapsulates an algorithm inside a class
- Encapsulate each one, and make them inchangeable to let clients and algorithms vary independently.
What is chain of responsibility?
A way of passing a request between a chain of objects until a job is handled
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
What is Mediator?
Defines an object that encapsulates how a set of objects interact
- Mediator promotes loose coupling by keeping objects from referring to each other explicitly by allow interaction independently
What is command?
Encapsulate a command request as an object
What is Iterator?
Sequentially access the elements of a collection
What is Visitor?
Defines new objects without a change of classes of the elements on which it operates
What is structural relationships?
Structural uses using inheritance to compose interfaces. to obtain a new functionality
What is Composite?
Compose object into a tree structure to represent whole-part.
Clients treat individual objects and compositions of object uniformly.
What is decorator?
Transparently argument objects with new responsibilities dynamically
What is Adapter?
Convert the interface of a class into another interface client expects; match interfaces with other classes known as Wrapper
What is Bridge?
Decouple an abstraction (interface) from its (physical) implementation so the two can vary independently.
What is Façade?
Façade is a single class that represents an entire subsystem that provides a unified interface to set of interfaces in a subsystem.
This defines a high-level interface that makes the subsystem easier to use.
What is proxy and the special name?
An object representing another object known as Surrogate
- Provide a surrogate or placeholder for another object to control access to it
- Wrap a complicated subsystem with a simpler interface
What is an abstarct factory?
Create families of related objects without specifying subclass names
Which relationship is identical?
COMPOSITION and DECORATOR are identical