Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungTCP vs UDP: The Two Ways to Move Data, and Why Neither Is "Better"(21.09.2026 um 09:31 Uhr)
Sichere ProgrammierungBukan Sekadar Variabel, Tapi Nyawa dari Aplikasi Kamu! 🚀(21.09.2026 um 09:36 Uhr)
Sichere ProgrammierungAI voice agent for customer service: what stops callers hanging up?(21.09.2026 um 09:42 Uhr)
Sichere ProgrammierungReading a small model's confidence instead of its prose(21.09.2026 um 09:47 Uhr)
Sichere ProgrammierungTCP vs UDP: The Two Ways to Move Data, and Why Neither Is "Better"(21.09.2026 um 09:31 Uhr)
Sichere ProgrammierungBukan Sekadar Variabel, Tapi Nyawa dari Aplikasi Kamu! 🚀(21.09.2026 um 09:36 Uhr)
Sichere ProgrammierungAI voice agent for customer service: what stops callers hanging up?(21.09.2026 um 09:42 Uhr)
Sichere ProgrammierungReading a small model's confidence instead of its prose(21.09.2026 um 09:47 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

How to apply SRP (Single Responsibility Principle) in Kotlin + Spring Boot project

How you know, the SRP is about "a class should have only one responsibility, do only one job, have only one reason for change, etc.". This principle is fundamental to writing clean, maintainable, and testable code. I read it in each book…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

How you know, the SRP is about "a class should have only one responsibility, do only one job, have only one reason for change, etc.". This principle is fundamental to writing clean, maintainable, and testable code. I read it in each book contains SOLID description.

But what does it mean: "one responsibility, one job, one reason for change"? Which of my own classes or those in the public libraries follow SRP and which do not?

For example, is LnkedList following SRP or not? Actually no. This class violates SRP because it has multiple responsibilities:




  • adding elements to the list,

  • removing elements from the list,

  • managing the list's head and tail,

  • provides some queue methods,

  • do many other things.



But I didn't find an answer to this fundamental question in many books for beginner developers.

I think it's a million-dollar mistake - the reason why we have thousands of programmers who know the description of the SRP but don't know what it should look like in code. These programmers write complicated and ugly code that is difficult to read, understand, test, and change.

You may have heard of "spaghetti code" or seen it. If not, I'll show it to you:




@Service
class SomeService {

fun f1() {
...\\ if-else blocks
val v2 = f2()
...
return v1
}

fun f2() {
...\\ if-else blocks
val v3 = f3()
...
return v2
}

fun f3() {
...
return v3
}
}






This class has three public functions that call each other and can be called from outside the class. If you want to modify one of these functions, you need to search for all the places it is used. And these places may look like the SomeService class...

Now, you understand how violating SRP can ruin your project from its begin. What can you do to avoid SRP violations? Only two rules need to be followed:

1) class should have only one public function




@Service
class DoSomeBusinessFunction(
private val doCommonFunction: DoCommonFunction,
) {

fun execute() {
...
val v2 = doOtherBusinessFunction.execute()
val v4 = f4(v2)
...
return v1
}

private fun f4(v2: Value2) {
...
return v4
}
}

@Service
class DoOtherBusinessFunction(
private val doCommonFunction: DoCommonFunction,
) {

fun execute() {
...
val v3 = doCommonFunction.execute()
...
return v2
}
}

@Service
class DoCommonFunction {

fun execute() {
...
return v3
}
}







2) If you want to create a function that behaves differently for different business scenarios, forget about trying to modify it and follow the "KISS" principle by using "magical" shortcuts like Ctrl + C, Ctrl+ V. Create a new class that has a new public function with a new behavior:




@Service
class DoSomeBusinessFunctionV1 {
private val doOtherBusinessFunction: DoOtherBusinessFunction,
) {

fun execute() {
...
val v2 = doOtherBusinessFunction.execute()
...
return v1
}
}

@Service
class DoSomeBusinessFunctionV2 {
private val doCommonFunction: DoCommonFunction,
) {

fun execute() {
...
val v3 = doCommonFunction.execute()
...
return v1
}
}






This approach keeps your code clean and gives you the following benefits:

1) simplifies code reading and understanding

2) simplifies unit tests writing

3) simplifies code changing

4) teaches junior developers to understand programming principles and apply them in practice.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to apply SRP (Single Responsibility Principle) in Kotlin + Spring Boot project

Thematisch verwandte Begriffe: apply, Single, Responsibility, Principle · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94030 | A security vulnerability has been detected in SerenityOS up to 3d83e4509…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick