Design Patters Flashcards
Why should we use design patterns?
We should use design patters since they increase code reuse by using common abstraction techniques.
What is model view controller
Separates presentation and interaction from system data.
- Model: system data and operations on that data
- View: how the data is presented to the use
- Controller: Manages user interaction (clicks, etc) with data.
What is problem description
describes when the design pattern is needed
What is solution description:
Explains what the solution is
What are the 3 types of design patterns?
Creational, Structural, Behavioral
What is creational design patterns
Abstracts the object instantiation process
What are some common creational patterns
Abstract factory
builder
factory method
prototype
singleton
What is factory method
Problem description:
- use when a class cannot anticipate the objects it must create.
Solution description:
- Defers the responsibility of creating objects to subclasses that know what to create.
example: pizza class has 3 sub classes : cheese, greek, peperoni
What is abstract factory
problem description:
- Use when your system must be configured with one of multiple families of objects
Solution description:
- Creates abstractions that hide the configuration details of the object families.
One store will create two types:
- Ny store will create ny borgar and ny pizza
another store will create:
- chicago store will create chicago borgar and chicago pizza
What are composite
Problem description: (STRUCTURAL)
- use to allow clietns to treat individual obkects and collections of them identically.
Solution description:
- Use an abstraction to hide the fact that an object is an aggregate of several objects.
Leaf-node relationship, directory and files
What is the template method
Problem description: (BEHAVIOURAL)
- Used to share common parts of an implementation while allowing subclasses to refine other parts.
Solution description:
- Common parts are defined in the superclass, which makes calls to abstract methods that deliver the other parts.
example: meal class is abstract, and combo1(), combo2() extend meal. and override the entree(), maincourse() and desert() methods.
What is the YAGNI principle.
- “You Aren’t Going to Need It”
- Design for the system you need today
- Revisit design periodically for opportunities to refactor and improve
What is cohesion and coupling
Cohesion is the degree to which a module relies on other members within the module to deliver its functionality.
- Keep HIGH
Coupling:
Degree to which a module relies on other modules to deliver functionality
- keep LOW
What are Structural patters
Structural:
Abstracts how classes and objects are composed to build larger structures
What are Behavioural patters
Behavioural:
Abstracts algorithms and assignment of responsibility among objects
What are 7 types of structural patterns
skip
What is cohesion
Degree to which a module relies on other members within the module to deliver its functionality
Desirable to keep HIGH
What is coupling
Degree to which a module relies on other modules to deliver functionality
Desirable to keep LOW
What is a schizo class
Problem description:
A class that contains disjoint sets of public methods that are used by disjoint sets of client classes
Solution description:
Refactor each set of methods into individual classes
What is a blob class
Name:
Blob (aka: god class)
Problem description:
A large class that is lacking cohesion or makes most of the processing decisions
Solution description:
Refactor Blob classes into a series of more cohesive classes