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