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