Flashcards
SOLID principles

Cards in this deck (37)
- 1What SOLID principle does this violate and what is a solution for it?The Single Principle.
Issue: Rectangle knows both how to draw and calculate

- 2What SOLID principle does this violate and what is a solution for it?The Open-Closed principle.
Issue: If you need to add a new flag, you must change a lot of the code. You need to add a new case and hard code the colours

- 3What SOLID principle does this violate and what is a solution for it?The Liskov Substitution principle.
Issue: Even though a Square is a Rectangle, they don’t behave the same way. Fx. if you need to calculate the area of a rectangle it is width * height - but for a square it is length * length.
A solution could be making a superclass called Shapes and let both inherit from them.
- 4What SOLID principle does this violate and what is a solution for it?The Interface Segregation principle.
Issue: TransferTransaction fx. inherits the methods RequestDepositAmt, RequestWithdrawalAmt that it doesn’t need (same for the other classes).

- 5What SOLID principle does this violate and what is a solution for it?The Dependency Inversion principle.
Issue: Stripe (Low-Level Module) is a service to process payment online (a payment tool). The Store (High-Level Module) depends fully on Stripe, which means that if Stripe stops working or is under maintenance, the entire Store will stop working.
Solution: Stripe is instead dependent on an interface, which Store also uses.

- 6What SOLID principle does this violate and what is a solution for it?The Dependency Inversion principle.
Issue: Stripe (Low-Level Module) is a service to process payment online (a payment tool). The Store (High-Level Module) depends fully on Stripe, which means that if Stripe stops working or is under maintenance, the entire Store will stop working.
Solution: Stripe is instead dependent on an interface, which Store also uses.

- 7What does KISS stand for?It's a principle: "Keep it simple stupid" OR "Keep it small and simple"
- 8What is the essence of the Unix philosophy?1. Make each program do one thing well.
2. Expect the output of every program to become the input to another, yet unknown program.
3. Design and build software, even operating systems, to be tried early, ideally within weeks.
4. Use tools in preference to unskilled help to lighten a programming task. - 9What does YAGNI stand for?It's a principle: "You aren't gonna need it"
A programmer should not add functionality until deemed necessary - 10What does CUPID stand for?It's a design principle:
Composable: plays well with others.
Unix philosophy: does one thing well.
Predictable: does what you expect.
Idiomatic: feels natural.
Domain-based: the solution domain models the problem domain in language and structure. - 11What are the goals with the SOLID principles?To eliminate the symptoms of poor design—design smells—and build the best designs for the current set of features.
To ensure that software has a good structure that is flexible, maintainable, and reusable. - 12What is the purpose of the SOLID principles?The SOLID gives us tools to diagnose rotting software.
Requirements are always changing, and our job is to make sure that our software can survive those changes. If the design of our software degrades because the requirements have changed, we are not being agile. - 13What is the problem with Design principles and Design smells?Highly subjective.
Cannot be measured objectively and automatically. - 14What are the steps in following agile practices?1. detect the problem by following agile practices.
2. diagnose the problem by applying design principles.
3. solve the problem by applying an appropriate design pattern. - 15Why does software rot?Requirements change in a way that the initial design did not anticipate.
Changes may be done quickly or by other developers.
Note, all of the symptoms above are subjective. They cannot be measured objectively and automatically. They always depend on the kind of the next task (change) that is applied. - 16What are the odors/smells of rotten software?Rigidity (The design is difficult to change)
Fragility (When software breaks in many places when a single change is made)
Immobility (The design is difficult to reuse)
Viscosity (It is easy to do the wrong thing but difficult to do the right thing - Viscosity of the software + Viscosity of the environment)
Needless complexity (When it contains elements that aren't currently useful - preparing for future potential changes)
Needless repetition (When the same code appears over and over again, in slightly different forms)
Opacity (Code that is difficult to understand) - 17How to do prevent software from rotting?By using Design principles - SOLID principles
- 18What does S stand for in SOLID?Single Responsibility Principle
- 19What is the intent of the Single Responsibility Principle?A class should have only one reason to change
- 20Typical signs something violates the Single Responsibility PrincipleOne class has multiple methods with different responsibilities.
Class with both business logic (fx. calculating) and persistence (fx. saving) - 21How does one try to solve the Single Responsibility Principle?Split into more classes with single responsibilities
- 22What does O stand for in SOLID?Open-Closed Principle
- 23What is the intent of the Open-Closed Principle?Open for extension, Closed for modification
- 24Typical signs something violates the Open-Closed PrincipleOne concrete class depends on another concrete class.
Has a lot of instanceof or switch statements that does something different for different (but similar) objects. - 25How does one try to solve the Open-Closed Principle?Inheritance! Add an interface, super class, or abstract super class.
Use a factory - 26What does L stand for in SOLID?Liskov Substitution Principle
- 27What is the intent of the Liskov Substitution Principle?Subtypes must be substitutable for their base types. - The superclass should not have functionality or attributes that the subclass doesn’t need
- 28Typical signs something violates the Liskov Substitution PrincipleA subclass has less behavior than its base class. Fx. if it can’t implement all the superclass’ methods, because they are not relevant/possible for the subclass to implement.
If it seems illogical that a subclass inherits from a superclass. Fx. if an orange is a subclass of an apple - 29How does one try to solve the Liskov Substitution Principle?The inheritance hierarchy should be restructured. Maybe other subclasses/interfaces instead.
- 30What does I stand for in SOLID?Interface Segregation Principle
- 31What is the intent of the Interface Segregation Principle?Clients should not be forced to depend on methods they do not use.
- 32Typical signs something violates the Interface Segregation PrincipleFat interfaces. Multiple classes implement the same interface but use different parts of it
- 33How does one try to solve the Interface Segregation Principle?Breaking the fat interface into many client-specific interfaces. The classes then implement the necessary interfaces.
- 34What does D stand for in SOLID?Dependency Inversion Principle
- 35What is the intent of the Dependency Inversion Principle?A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions. - 36Typical signs something violates the Dependency Inversion PrincipleIf it seems like “the important class” depends on a more specific, detailed class
- 37How does one try to solve the Dependency Inversion Principle?“Turn the arrow around” by making an interface, that the high level and low-level module depends on
Information
- Description
- 3rd semester BDSA Flashcards on SOLID principles, created by Turið Højgaard on 27/12/2022.
- Created by
- Turið Højgaard
- Views
- 3
- Rating