SOLID Principles

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/59

flashcard set

Earn XP

Description and Tags

acronym

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

60 Terms

1
New cards
What does 'S' in SOLID stand for?
The 'S' in SOLID stands for the **Single Responsibility Principle (SRP)**.
2
New cards
What is the core definition of the Single Responsibility Principle (SRP)?
The SRP states that "**there should never be more than one reason for a class to change**".
3
New cards
In simpler terms
what does SRP mean for a class
4
New cards
Name one key benefit of applying the Single Responsibility Principle.
Applying SRP improves **maintainability**
5
New cards
What is an example of an anti-pattern that violates SRP?
A **"Swiss knife" class** is an anti-pattern that violates SRP by bundling many responsibilities into a single unit
6
New cards
Does SRP imply that a class should only have one method?
No
7
New cards
When might it be unwise to strictly apply the Single Responsibility Principle?
It is **not wise to apply SRP if there is no symptom of a problem**
8
New cards
Who is credited with introducing the basic SOLID principles?
The basic SOLID principles were introduced by **Robert C. Martin**
9
New cards

How is a "reason to change" defined in the context of SRP?

In SRP, a **"reason to change" is defined as a responsibility**.

10
New cards

What undesirable state can an application reach if SRP is not followed?

An application can become an **unmanageable "tangled mess" or "plate of spaghetti"**, making it difficult to maintain and extend.

11
New cards

When should developers exercise caution or judgment when applying SRP?

It is **not wise to strictly apply SRP if there is no symptom of a problem**, as over-application can lead to needless complexity or a "class explosion".

12
New cards

How does the Single Responsibility Principle relate to code cohesion?

Applying SRP leads to **high cohesion**, where elements within a module are functionally related and belong together, making the module easier to reason about.

13
New cards
"What does 'I' in SOLID stand for?"
"The 'I' in SOLID stands for the **Interface Segregation Principle (ISP)**."
14
New cards
"What is the core principle of the Interface Segregation Principle (ISP)?"
"The ISP states that **\"clients should not be forced to depend upon interfaces that they do not use\"**."
15
New cards
"In simpler terms
what does ISP mean for interfaces?"
16
New cards
"What is the main problem ISP aims to solve?"
"ISP aims to solve the problem where **clients are forced to implement methods or interfaces that are not relevant to their specific needs**."
17
New cards
"What is a \"fat interface\" in the context of ISP?"
"A **\"fat interface\"** is an interface that is too large and not cohesive
18
New cards
"Name one key benefit of applying the Interface Segregation Principle."
"Applying ISP leads to **decoupling** by reducing dependencies between classes
19
New cards
"How does ISP relate to the Single Responsibility Principle (SRP)?"
"ISP is **\"fairly similar\" to SRP**
20
New cards
"Provide an example of how a client might be forced to depend on an interface it doesn't use."
"The ASP.NET 2.0 Membership Provider is cited as an example of a **\"fat interface\"** that forced users to implement many methods they didn't need
21
New cards
"What is the recommended approach to fix an ISP violation?"
"The recommended approach is to **\"break down large interfaces into smaller
22
New cards
"How can ISP help reduce coupling in software design?"
"ISP reduces coupling by **allowing for more targeted implementations of interfaces** and ensuring clients only depend on the specific methods they use."
23
New cards
"Does ISP suggest that an interface should be defined by the client's needs or the implementer's capabilities?"
"ISP suggests an interface should be **\"more closely related to the code that uses it than the code that implements it\"**
24
New cards
"Who introduced the Interface Segregation Principle?"
"The Interface Segregation Principle (ISP) is one of the S.O.L.I.D design principles pioneered by **Robert C. Martin**
25
New cards
"What does 'L' in SOLID stand for?"
"The 'L' in SOLID stands for the **Liskov Substitution Principle (LSP)**."
26
New cards
"What is the core definition of the Liskov Substitution Principle (LSP)?"
"The LSP states that **objects of a superclass shall be replaceable with objects of its subclasses without breaking the application**."
27
New cards
"Who is credited with introducing the Liskov Substitution Principle?"
"The principle was introduced by **Barbara Liskov** in 1987
28
New cards
"What must be true for objects of a subclass to adhere to LSP?"
"Objects of subclasses must **behave in the same way as the objects of their superclass**."
29
New cards
"How do overridden methods in subclasses relate to input parameters according to LSP?"
"An overridden method in a subclass must **accept the same or less restrictive input parameter values** as the method of the superclass."
30
New cards
"How do overridden methods in subclasses relate to return values according to LSP?"
"The return value of a subclass's method must **comply with the same or stricter rules** as the return value of the superclass's method."
31
New cards
"Name one key benefit of applying the Liskov Substitution Principle."
"Applying LSP ensures **polymorphism**
32
New cards
"How does LSP ensure reliability in software design?"
"LSP ensures reliability by guaranteeing that **replacing a superclass object with a subclass object won't break the program**."
33
New cards
"What is a common indicator of an LSP violation in code?"
"A common indicator is when **type-checking logic (e.g.
34
New cards
"Can a function taking a base class parameter use a derived class object that enforces stricter input validation and still adhere to LSP?"
"No
35
New cards
"How does the example of a `Rectangle` and `Square` class often illustrate an LSP violation?"
"If a `Square` subclass modifies its `setWidth` or `setHeight` methods to keep sides equal
36
New cards
"How does the Liskov Substitution Principle relate to the Open/Closed Principle (OCP)?"
"LSP is an **extension of OCP**
37
New cards
"What does 'I' in SOLID stand for?"
"The 'I' in SOLID stands for the **Interface Segregation Principle (ISP)**."
38
New cards
"What is the core definition of the Interface Segregation Principle (ISP)?"
"The ISP states that **\"clients should not be forced to depend upon interfaces that they do not use\"**."
39
New cards
"In simpler terms
what does ISP mean for interface design?"
40
New cards
"What kind of interfaces does ISP advocate for?"
"ISP advocates for **many small
41
New cards
"What is a \"fat interface\" and why does ISP aim to avoid it?"
"A **\"fat interface\"** is an interface that is too large and not cohesive
42
New cards
"Name one key benefit of applying the Interface Segregation Principle."
"Applying ISP leads to **decoupling**
43
New cards
"How does ISP relate to code maintainability?"
"ISP improves maintainability by **reducing dependencies between classes** and making the codebase easier to manage through smaller
44
New cards
"How does ISP help reduce unnecessary dependencies?"
"ISP avoids unnecessary dependencies by ensuring that **clients only depend on interfaces (and their methods) that are directly relevant to their needs**."
45
New cards
"Provide an example of a real-world anti-pattern that violates ISP."
"The **ASP.NET 2.0 Membership Provider** is cited as a real-world example of a \"fat interface\" that forced users to implement many methods they didn't need."
46
New cards
"How is the Interface Segregation Principle similar to the Single Responsibility Principle (SRP)?"
"ISP is **\"fairly similar\" to SRP**
47
New cards
"Who is credited with introducing and popularizing the Interface Segregation Principle?"
"The Interface Segregation Principle was introduced by **Robert C. Martin**
48
New cards
"What is the recommended action to fix a \"fat interface\" that violates ISP?"
"To fix a fat interface violating ISP
49
New cards
"What does 'D' in SOLID stand for?"
"The 'D' in SOLID stands for the **Dependency Inversion Principle (DIP)**."
50
New cards
"What are the two core tenets of the Dependency Inversion Principle?"
"The DIP states that **high-level modules should not depend upon low-level modules
51
New cards
"Who introduced the Dependency Inversion Principle?"
"The Dependency Inversion Principle was pioneered and first collected into a written work by **Robert C. Martin**
52
New cards
"What is a 'high-level module' in the context of DIP?"
"**High-level modules** (or classes) implement the **business rules or logic** in a system."
53
New cards
"What is a 'low-level module' in the context of DIP?"
"**Low-level modules** (or classes) deal with **more detailed operations**
54
New cards
"What undesirable traits of software design does DIP aim to alleviate?"
"DIP aims to alleviate problems of **bad design** such as software being **rigid** (changes affect too many parts)
55
New cards
"How does DIP achieve loose coupling between modules?"
"DIP reduces coupling by making both high-level and low-level modules **depend upon abstractions (like interfaces or abstract classes)** instead of concrete implementations."
56
New cards
"What is the main benefit of applying the Dependency Inversion Principle?"
"Applying DIP leads to **loose coupling**
57
New cards
"How is the Dependency Inversion Principle related to Inversion of Control (IoC) containers?"
"**IoC containers** are **tools that assist applications in adhering to DIP** by managing the creation and injection of dependencies
58
New cards
"What design pattern often emerges when applying DIP to solve the 'details should depend on abstractions' tenet?"
"The **Strategy pattern** often shows up in designs when following DIP
59
New cards
"Why is the principle called 'dependency inversion'?"
"It's called 'dependency inversion' because it **inverts the traditional dependency structure** where high-level modules depend on low-level modules; instead
60
New cards
"How does DIP relate to other SOLID principles like Open/Closed Principle (OCP) and Single Responsibility Principle (SRP)?"
"DIP is considered a **natural progression** of LSP