Skip to content

Commit 8f4ed5b

Browse files
committed
Extend section about single responsibility principle
1 parent 0e02a93 commit 8f4ed5b

File tree

1 file changed

+11
-0
lines changed
  • oop-essentials/03-general-principles

1 file changed

+11
-0
lines changed

oop-essentials/03-general-principles/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ We shall first describe the principles and then relate them to the preceding cas
1313
* The components are relatively small pieces of code that are easy to scan and understand.
1414
* The component where a change/fix would need to be implemented is easy to identify and modifications can be made more quickly.
1515

16+
While the Single Responsibility Principle (SRP) traditionally applies to classes, it should also be extended to other components like functions or modules. Each function should do one thing and do it well, and each module should encapsulate a single aspect of the system's functionality. This broad application of SRP ensures that systems remain modular, easier to understand, and simpler to maintain.
17+
18+
In this sense, SRP can be understood as a specific application of the broader **Separation of Concerns Principle** and an alternative description
19+
of SRP would be:
20+
21+
“Gather together the things that change for the same reasons. Separate those things that change for different reasons.”
22+
1623
2. **Open-Closed Principle**
1724

1825
“Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification,” i.e. entities should allow their behaviour to be extended without modifying the source code.
@@ -77,6 +84,10 @@ This is closely tied to the *principle of least surprise*, which calls for desig
7784
Understand people as part of the system, and choose a design that matches people's expectations, experience, and mental models.
7885
If possible, the design should prefer idiomatic language constructs over exotic, non-standard ones that aren't easily understood - even if the exotic ones may solve a problem slightly more elegantly.
7986

87+
# SLAP (Single Level of Abstraction Principle)
88+
89+
The **Single Level of Abstraction Principle** states, that a function should either be low-level function itself (think of a pure procedural code snippet like a for loop) or should only call other (possible low-level) functions. One should avoid a mixture of these different levels.
90+
8091
# Extreme Programming (XP)
8192

8293
YAGNI is one of the core principles of extreme programming (aka XP), which addresses not only principles pertaining to code but also collaboration.

0 commit comments

Comments
 (0)