Questions About Design Patterns Flashcards

1
Q

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

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

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 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 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, 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

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

Many state that, in Object-Oriented Programming, 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

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 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

The ability to change 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

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

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

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

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 re-worded 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 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