Design Patterns Flashcards

1
Q

Globals Are Evil

Why are global and static objects evil? Can you show it with a code example?

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

Inversion of Control:

Tell me about Inversion of Control and how it improves the design of code.

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

Law of Demeter:

The Law of Demeter (the Principle of Least Knowledge) states that each unit should have only limited knowledge about other units and it should only talk to its immediate friends (sometimes stated as “don’t talk to strangers”).

Would you write code violating this principle, show why it is a bad design, and then fix it?

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

Active-Record:

Active-Record is the design pattern that promotes objects to include functions such as Insert, Update, and Delete, and properties that correspond to the columns in some underlying database table.

In your opinion and experience, which are the limits and pitfalls of this pattern?

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

Data-Mapper:

Data-Mapper is a design pattern that promotes the use of a layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. On the contrary, in Active-Record objects directly incorporate operations for persisting themselves to a database, and properties corresponding to the underlying database tables.

Do you have an opinion on those patterns? When would you use one instead of the other?

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

Billion Dollar Mistake:

Why is it often said that the introduction of null is a “billion-dollar mistake”? Would you discuss the techniques to avoid it, such as the Null Object Pattern introduced by the GOF book, or Option types?

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

Inheritance vs Composition:

Many states that, in Object-Oriented Programming, the composition is often a better option than inheritance. What’s your opinion?

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

Anti-corruption Layer:

What is an Anti-corruption Layer?

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

Singleton:

Singleton is a design pattern that restricts the instantiation of a class to one single object. Writing a Thread-Safe Singleton class is not so obvious. Would you try?

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

Data Abstraction:

The ability to change the implementation without affecting clients is called Data Abstraction. Produce an example violating this property, then fix it.

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

Don’t Repeat Yourself:

Write a snippet of code violating the Don’t Repeat Yourself (DRY) principle. Then, fix it.

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

Dependency Hell:

How would you deal with Dependency Hell?

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

Goto is Evil:

Is goto evil? You may have heard of the famous paper “Go To Statement Considered Harmful” by Edsger Dijkstra, in which he criticized the use of the goto statement and advocated structured programming instead. The use of goto has always been controversial, so much that even Dijkstra’s letter was criticized with articles such as “‘GOTO Considered Harmful’ Considered Harmful”.

What’s your opinion on the use of goto?

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

Robustness Principle:

The robustness principle is a general design guideline for software that recommends “be conservative in what you send, be liberal in what you accept”. It is often reworded as “be a tolerant reader and a careful writer”. Would you like to discuss the rationale of this principle?

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

Separation of Concerns:

Separation of Concerns is a design principle for separating a computer program into distinct areas, each one addressing a separate concern. There are a lot of different mechanisms for achieving Separation of Concerns (use of objects, functions, modules, or patterns such as MVC and the like).

Would you discuss this topic?

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