Design Patterns & Principles Flashcards

1
Q

STRATEGY design pattern

A
  • Defines a family of algorithms, encapsulates each one, and makes them interchangeable through client code at runtime.
  • Involves using interfaces like Comparators and making different classes for each strategy.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ITERATOR design pattern

A

Provide a way to access elements of an aggregate object without exposing its underlying encapsulation using ITERABLE and ITERATOR

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

Interface segregation principle

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

NULL OBJECT design pattern

A
  • only applicable when there is a type hierarchy
  • create a class to represent a null object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

FLYWEIGHT design pattern

A
  • used to ensure uniqueness of objects of a class
  • components:
    1. private constructor
    2. static flyweight store: to store collection of flyweight objects
    3. static access method: returns unique flyweight object that corresponds to identification key. Usually checks whether it already exists in the store, creates one if it does not.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

SINGLETON design pattern

A
  • used to ensure there is only one instance of a given class at any point in the execution of code.
  • components:
    1. private constructor
    2. private static final global variable: to hold reference to single instance
    3. static accessor method: usually called instance() that returns the singleton instance.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

COMPOSITE design pattern

A
  • composite class that implements the interface which contains an aggregate of that interface -> it can store other classes that implement that interface
  • two ways to specify which instances of the interface form the aggregate:
    1. add method in composite class
    2. initialize through constructor in composite class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DECORATOR design pattern

A
  • when we want to decorate some object with additional features while being able to treat the decorated object like any other object of the undecorated type
  • Decorator class implements the interface and contains an aggregate of instances of that interface
  • the field that stores a reference to the decorated object is final and initialized in the constructor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PROTOTYPE design pattern

A
  • relying on a polymorphic copying mechanism and create new instances of an object of interest by copying a prototype object
  • when you need to create objects whose type may not be known at compile time
  • use dependency injection to inject an object into a class via its constructor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

COMMAND design pattern

A
  • have a Command interface with methods like execute(), undo(), getDescription()
  • define specific commands as objects/classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

TEMPLATE METHOD design pattern

A

put all common code in the superclass and define some hooks to allow subclasses to provide specialized functionality where needed
- declare template method to be final(cannot be overidden by subclasses)
- the method implemented by subclasses is protected and abstract

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

OBSERVER design pattern

A
  • create an Observer interface
  • model holds an aggregate of Observers
  • when a method is called that changes the model, a notification method is called to notify specific observers of the change through their callback methods.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

VISITOR design pattern

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