Introduction Flashcards

1
Q

What is a design pattern ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the four elements of a design pattern ?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In MVC What is the model ?

A

It is the application object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In MVC What is the view ?

A

The view is the screen presentation of the application object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In MVC What is the controller ?

A

The controller defines the way the user interface reats to user input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the relationship/communication between the view and the model ?

A

A subscribe/notification protocol.

Whenever the model’s data changes, the model notifies the views that subscribed to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the design pattern behind the relationship between the View and the Model ?

A

It is the Observer pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe briefly the observer pattern

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which design pattern address the following problem : Grouping objects and treat the group like an individual object ?

A

The composite pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where do we find the composite pattern in MVC

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which pattern describe well the relationship between view and controller ?

A

The strategy pattern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe succinctly the Strategy pattern ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the 3 main design Patterns in the MVC ?

A

Observer, Composite, Strategy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are some additional Patterns we can see in MVC ?

A

Factory, Decorator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the 13 elements necessary to describe a design pattern ?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the intent of the Abstract Factory pattern ?

A

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the intent of the Adapter pattern ?

A

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the intent of the Bridge pattern ?

A

Decouple an abstraction from its implementation so that the two can vary independently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the intent of the builder pattern ?

A

Separate the construction of a complex object from its representation so that the same construction process can create different representations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the intent of the pattern “Chain of Responsibility”

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the intent of the Command pattern ?

A

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the intent of the composite pattern ?

A

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the intent of the composite pattern ?

A

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the intent of the decorator pattern ?

A

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the intent of the Façade pattern ?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the intent of the Factory method pattern ?

A

Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is the intent of the Flyweight pattern ?

A

Use sharing to support large numbers of fine-grained objects efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the intent of the interpreter pattern ?

A

Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the intent of the iterator pattern ?

A

Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

30
Q

What is the intent of the mediator pattern ?

A

Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.

31
Q

What is the intent of the memento pattern ?

A

Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.

32
Q

What is the intent of the observer pattern ?

A

Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

33
Q

What is the intent of the Prototype pattern ?

A

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

34
Q

What is the intent of the Proxy pattern ?

A

Provide a surrogate or placeholder for another object to control access to it.

35
Q

What is the intent of the Singleton pattern ?

A

Ensure a class only has one instance, and provide a global point of access to it.

36
Q

What is the intent of the State pattern ?

A

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

37
Q

What is the intent of the Strategy pattern ?

A

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

38
Q

What is the intent of the Template Method pattern ?

A

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

39
Q

What is the intent of the Visitor pattern ?

A

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

40
Q

What are the 2 criterias used to classify design Patterns ?

A
  • The purpose (creational, structural, behavioral)

- The scope (class or object)

41
Q

What is the concern of creational Patterns ?

A

Creational patterns concern the process of object creation.

42
Q

What is the concern of structural Patterns ?

A

Structural patterns deal with the composition of classes or objects.

43
Q

What is the concern of behavioral Patterns ?

A

Behavioral patterns characterize the ways in which classes or objects interact and distribute responsibility.

44
Q

List some problems design Patterns come to solve

A
  • Finding Appropriate Objects
  • Determining Object Granularity
  • Specifying Object Interfaces
  • Specifying Object Implementations
  • Putting Reuse Mechanisms to Work
  • Designing for Change
45
Q

What is the difference between class inheritance and interface inheritance

A

Class inheritance defines an object’s implementation in terms of another object’s implementation. In short, it’s a mechanism for code and representation sharing. In contrast, interface inheritance (or subtyping) describes when an object can be used in place of another.

46
Q

What is the différence between a class and a type ?

A

An object’s class defines how the object is implemented. The class defines the object’s internal state and the implementation of its operations. In contrast, an object’s type only refers to its interface—the set of requests to which it can respond. An object can have many types, and objects of different classes can have the same type.

47
Q

Explain this OO design principle: Program to an interface, not an implementation.

A

It means that you should not declare variables to be instances of particular concrete classes. Instead, commit only to an interface defined by an abstract class.

48
Q

Which category of patterns allows to implement this oo design principle: Program to an interface, not an implementation ?

A

Creational patterns.

Creational patterns ensure that your system is written in terms of interfaces, not implementations.

49
Q

What is an operation’s signature ?

A

It is the set made by the operation’s name, the objects this operation takes as parameters, and the operation’s return value.

50
Q

What is an interface ?

A

The set of all signatures defined by an object’s operations

50
Q

What is an interface ?

A

The set of all signatures defined by an object’s operations

51
Q

What is a type ?

A

A type is a name used to denote a particular interface

52
Q

What is dynamic binding ?

A

The run-time association of a request to an object and one of its operations

53
Q

List 2 exemples of less obvious objectd that design Patterns can help you capture ?

A

Objects that represent a process or algorithm. The Strategy (315) pattern describes how to implement interchangeable families of algorithms.

The State (305) pattern represents each state of an entity as an object.

These objects are seldom found during analysis or even the early stages of design;

54
Q

List some creational design patterns ?

A
Factory Method
Abstract Factory
Builder
Prototype
Singleton
55
Q

List some structural design patterns

A
Adapter (class)
Adapter (object)
Bridge
Composite
Decorator 
Facade 
Flyweight
Proxy
56
Q

List some behavioral design patterns

A
Interpreter
Template method
Chain of Responsibility 
Command
Iterator
Mediator
Memento 
Observer
State
Strategy
Visitor
57
Q

What are the 2 basic techniques for reusing functionalities in OO systems ?

A

Class inheritance and Object composition

58
Q

What is white-box reuse ?

A

Inheritance

59
Q

What is black-box reuse ?

A

Composition

60
Q

What are the advantages of class inheritance ?

A
  • Straightforward to use
  • Easier to modify the implementation being reused: when a subclass overrides some but not all operations, it can affect the operations it inherits as well, assuming they call the overridden operations.
61
Q

What are the disadvantages of class inheritance ?

A
  • you can’t change the implementations inherited from parent classes at run-time, because inheritance is defined at compile-time.
  • generally worse: parent classes often define at least part of their subclasses’ physical representation
62
Q
Explain this second principle of oo design: 
"Favor object composition over class inheritance."
A

Ideally, you shouldn’t have to create new components to achieve reuse. You should be able to get all the functionality you need just by assembling existing components through object composition. But this is rarely the case, because the set of available components is never quite rich enough in practice. Reuse by inheritance makes it easier to make new components that can be composed with old ones. Inheritance and object composition thus work together.

63
Q

What is delegation ?

A

Delegation is a way of making composition as powerful for reuse as inheritance. In delegation, 2 objects are involved in handling a request: a receiving object delegates operations to its delegate.

64
Q

What are the other names of “parametized types” ?

A

Generics, Templates.

65
Q

Liste some causes of redesign in oo programming

A

Creating an object by specifying a class explicitly.

Dependence on specific operations.

Dependence on hardware and software platform

Dependence on object representations or implementations.

Algorithmic dependencies.

Tight coupling.

Extending functionality by subclassing

Inability to alter classes conveniently

66
Q

What is a toolkit ?

A

A toolkit is a set of related and reusable classes designed to provide useful, general-purpose functionality.

An example of a toolkit is a set of collection classes for lists, associative tables, stacks, and the like. The C++ I/O stream library is another example.

67
Q

What is a framework ?

A

A framework is a set of cooperating classes that make up a reusable design for a specific class of software [Deu89, JF88].

For example, a framework can be geared toward building graphical editors for different domains like artistic drawing, music composition, and mechanical CAD [VL90, Joh92].
Another framework can help you build compilers for different programming languages and target machines [JML92].

68
Q

What makes the difference between a toolkit and à framework ?

A

Toolkits don’t impose a particular design on your application; they just provide functionality that can help your application do its job. They let you as an implementer avoid recoding common functionality. Toolkits emphasize code reuse. They are the object-oriented equivalent of subroutine libraries.

The framework dictates the architecture of your application. It will define the overall structure, its partitioning into classes and objects, the key responsibilities thereof, how the classes and objects collaborate, and the thread of control. A framework predefines these design parameters so that you, the application designer/implementer, can concentrate on the specifics of your application. The framework captures the design decisions that are common to its application domain. Frameworks thus emphasize design reuse over code reuse, though a framework will usually include concrete subclasses you can put to work immediately.

69
Q

What are the différences between design patterns and frameworks ?

A

Design patterns are more abstract than frameworks. Frameworks can be embodied in code, but only examples of patterns can be embodied in code.

Design patterns are smaller architectural elements than frameworks. A typical framework contains several design patterns, but the reverse is never true

Design patterns are less specialized than frameworks