Design Patterns Flashcards

1
Q

What is a Design Pattern?

A

It is an organized way to present things or build things. Vocabulary for talking about things or building things. Separate the things that change and the things that don’t change. You are more efficient knowing this.

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

Architectural “Macroscale” Patterns?

A

You look at the growth structure from far away. Model view controller is an example of this. Pipe & Filter is an example of this. Pump -> Filter -> Filter -> Pump. Filters change the data. Event-based like in javacsript. Layering are all examples.

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

Gang of 4 Patterns?

A

Structural, Behavioral, and Creational.

23 Structural Design Patterns.

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

What is technical debt?

A

When you know the right thing to do is too long and instead you do the quick dirty option. Technical debt accumulates and makes anti-patterns. Viscosity, Dryness, Immobility, Needless reputation.

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

What is UML

A

Unified Modeling Language: notation for describing various artifacts in OOP systems.

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

DO inheritances follow Single Responsibility Class?

A

Yes we only let one model do a specific things. Even though they inherit.

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

What is Cohesion?

A

cohesion refers to the degree to which the elements of a module belong together. Thus, cohesion measures the strength of relationship between pieces of functionality within a given module. For example, in highly cohesive systems functionality is strongly related

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

Why doesn’t it work in javascript to call a method with no parenthesis?

A

it would be an expression whose value is the function itself, rather than a call to the function. It is becuase javascript functions are first class functions.

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

4 Categories of Maintenance?

A
  1. Corrective Maintenance where you repair and fix bigs
  2. Perfective Maintenance where you expand functionality
  3. Adaptive where you cope with changing environment
  4. Preventative where you improve the needs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Composition?

A

The owned objects are usually destroyed when the owning object is destroyed.

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

What is aggregation?

A

Owned Object survives destruction of owning object.

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

How do you structure University to Departments in UML Model?

A

University has many departments, Departments have one University.
The Departments can’t survive without university, so composition.

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

What is the Single Responsibility Principle?

A

A class housed have one and only one reason to change. A sign is a data clump traveling with the calls to this class and a fix is to extract classes.

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

What is Open/Closed Principle?

A

You should be able to extend the behavior of classes without modifying existing code on which other classes or apps depend on it.

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

Difference between the Template Method Strategy & the Delegate Strategy?

A

Template Method is when the class has the basic game plan and then it is customized by delegating specific behaviors to the sub classes. In Decorator, each subclass provides functionality of its own, but delegate to the parent class for basic functionality.

Template - Class delegates behavior to descendants
Decorator - Subclass delegate behavior to parent.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Liskov Substitution?

A

A method designed to work on an object of Type T should also work on a n object of subtype of T. Subclasses destructively override behavior of parent. Classic example is trying to make a square form rectangle.

17
Q

Why is Forward-able in the standard Ruby library provided as a module not a class?

A

It would be awkward.

18
Q

Difference Between Module and Class?

A

Module provides methods you can use across a number of classes. Class has its own methods.

19
Q

What is Dependency Injection Principle?

A

If two classes depend on each other but their implementations change, it would be better for them to both depend on a separate abstract interface that is “injected” between them. Instead of hardwiring a dependency into the source code, you just inject the right value at run time and in the mean time you have inputs in that class for those values.

20
Q

What is the Demeter Principle?

A

A method can call other methods in its own class, and methods on the classes of its own instance variables. It like having an attribute of a certain class as one of your attributes. You can call self.wallet.balance for your balance.