Software design Flashcards

1
Q

What are the parts of the CRC cards?

A

Top: class name

Left: responsibilities

Right: collaborators (other classes it interacts with)

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

What is polymorphism?

A

Polymorphism is the capability to provide multiple implementation of an action and to select the correct implementation based on the surrounding context.

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

What is the difference between an interface and an abstract class?

A

An interface declares a set of related methods, outside of any class. An abstract class is an incomplete class definition that declares but does not define all its methods.

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

What is the problem with multiple inheritance?

A

It can lead to ambiguity. If both superclasses have a variable with the same name, you have to prefix it with the superclass name when accessing, as there’ll be two separate instances of the same name. In case a a virtual base classes there will be a shared instance.

Other ambiguity is which constructor is called first or some members may be accidentally hidden from derived classes.

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

What are design patterns?

A

Design patterns are guidelines for identifying and solving common design problems in object-oriented programming.

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

Why are design patterns useful?

A
  1. they help to solve common software design problems based on the collected wisdom of many programmers
  2. design patterns provide a concise vocabulary for discussing design problems and their solutions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the advantage of using a decorator pattern instead of inheritance?

A

A decorator can be used to alter the behaviour of an object in runtime instead of compile time.

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

Examples of singleton pattern usage.

A
  • gatekeeper to shared resources
  • central communication hub
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the law of demeter?

A

A module should not know about the innards of objects it manipulates.

Specifically a method f of a class C should only call the methods of these:

  • C
  • An object created by f
  • An object passed as an argument to f
  • An object held in an instance variable of C
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the Single Responsibility Principle?

A

A class should have one and only one reason to change.

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

What is the Open/Close principle?

A

We should add new funcionality by adding new code, not by editing old code.

“Modules shold be open for extension, but closed for modifications”

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

Tell an example that break the Open/close principle?

A

We have shape classes and a method that calculates the area of the shape using swtch statements based on the shape type that is passed to the method. When a new shape type is introduced, then you have to modify the code responsible for calculating the area.

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

What is Liskov Substitution Principle?

A

All derived classes must be substitutable for their base classes.

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

What is Dependency Inversion Principle?

A

Details should depend on abstractions. Abstractions should not depend on details.

  1. High level modules should not depend on low-level modules. Both should depend on abstractions.
  2. Abstractions should not depend on details. Details should depend on abstractions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly