Introduction Flashcards
What is a design pattern ?
A design pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.
It is a description of communicating objects and classes that are customized to solve a general design problem in a particular context.
What are the four elements of a design pattern ?
- The pattern name: it enrich the design vocabulary and allow to discuss design at a higher level of abstraction.
- The problem: describes when to apply the pattern.
- The solution: describes the elements that make up the design, their relationships, responsibilities and collaborations.
- The consequences: the results and trade-offs of applying the pattern.
In MVC What is the model ?
It is the application object.
In MVC What is the view ?
The view is the screen presentation of the application object.
In MVC What is the controller ?
The controller defines the way the user interface reats to user input.
What is the relationship/communication between the view and the model ?
A subscribe/notification protocol.
Whenever the model’s data changes, the model notifies the views that subscribed to it.
What is the design pattern behind the relationship between the View and the Model ?
It is the Observer pattern.
Describe briefly the observer pattern
It decouple objects so that changes to one can affect any number of others without requiring the changed object to know details of the others.
Which design pattern address the following problem : Grouping objects and treat the group like an individual object ?
The composite pattern
Where do we find the composite pattern in MVC
In the View.
Views can be nested. For example, a control panel of buttons might be implemented as a complex view containing nested button views.
MVC supports nested views with the CompositeView class, a subclass of View. CompositeView objects act just like View objects; a composite view can be used wherever a view can be used, but it also contains and manages nested views.
Which pattern describe well the relationship between view and controller ?
The strategy pattern
Describe succinctly the Strategy pattern ?
A Strategy is an object that represents an algorithm. It’s useful when you want to replace the algorithm either statically or dynamically, when you have a lot of variants of the algorithm, or when the algorithm has complex data structures that you want to encapsulate.
What are the 3 main design Patterns in the MVC ?
Observer, Composite, Strategy
What are some additional Patterns we can see in MVC ?
Factory, Decorator
What are the 13 elements necessary to describe a design pattern ?
- The pattern Name and Classification
- The intent of the pattern
- The “Also known as”
- The motivation
- The applicability
- The structure
- The participants
- The collaborations
- The consequences
- The implementation
- The sample codes
- The known uses
- The related patterns
What is the intent of the Abstract Factory pattern ?
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
What is the intent of the Adapter pattern ?
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
What is the intent of the Bridge pattern ?
Decouple an abstraction from its implementation so that the two can vary independently.
What is the intent of the builder pattern ?
Separate the construction of a complex object from its representation so that the same construction process can create different representations.
What is the intent of the pattern “Chain of Responsibility”
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
What is the intent of the Command pattern ?
Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
What is the intent of the composite pattern ?
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
What is the intent of the composite pattern ?
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
What is the intent of the decorator pattern ?
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
What is the intent of the Façade pattern ?
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
What is the intent of the Factory method pattern ?
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
What is the intent of the Flyweight pattern ?
Use sharing to support large numbers of fine-grained objects efficiently.
What is the intent of the interpreter pattern ?
Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language.