Software design Flashcards
What are the parts of the CRC cards?
Top: class name
Left: responsibilities
Right: collaborators (other classes it interacts with)
What is polymorphism?
Polymorphism is the capability to provide multiple implementation of an action and to select the correct implementation based on the surrounding context.
What is the difference between an interface and an abstract class?
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.
What is the problem with multiple inheritance?
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.
What are design patterns?
Design patterns are guidelines for identifying and solving common design problems in object-oriented programming.
Why are design patterns useful?
- they help to solve common software design problems based on the collected wisdom of many programmers
- design patterns provide a concise vocabulary for discussing design problems and their solutions
What is the advantage of using a decorator pattern instead of inheritance?
A decorator can be used to alter the behaviour of an object in runtime instead of compile time.
Examples of singleton pattern usage.
- gatekeeper to shared resources
- central communication hub
What is the law of demeter?
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
What is the Single Responsibility Principle?
A class should have one and only one reason to change.
What is the Open/Close principle?
We should add new funcionality by adding new code, not by editing old code.
“Modules shold be open for extension, but closed for modifications”
Tell an example that break the Open/close principle?
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.
What is Liskov Substitution Principle?
All derived classes must be substitutable for their base classes.
What is Dependency Inversion Principle?
Details should depend on abstractions. Abstractions should not depend on details.
- High level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.