0Pricing
Clean Architecture & Design Patterns in Practice · Lektion

Überblick über die SOLID-Prinzipien

Erhalten Sie eine Einführung in die fünf SOLID-Prinzipien: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation und Dependency Inversion.

Überblick über die SOLID-Prinzipien ist eine kostenlose Clean Architecture & Design Patterns in Practice-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Clean Architecture & Design Patterns in Practice-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Clean Architecture & Design Patterns in Practice-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

What are SOLID Principles?

The SOLID principles are five design guidelines for software that’s easy to maintain, understand, and extend. Think of them as a path to cleaner code.

Why SOLID Matters

Applying SOLID gives you code that’s easier to understand, simpler to test, more flexible to change, and friendlier to teamwork. It’s the bedrock of good OO design.

S: Single Responsibility Principle (SRP)

The Single Responsibility Principle: a class should have one reason to change. Don’t mix calculating data and saving it — split those concerns apart.

SRP in Action: Simple Report

This SimpleReport obeys SRP: its only job is generating report content. Printing and saving are someone else’s responsibility.

public class SimpleReport {
  private String content;

  public SimpleReport(String content) {
    this.content = content;
  }

  // This class's single responsibility is to generate/represent the report content
  public String generateReportContent() {
    return "Report: " + content;
  }

  public static void main(String[] args) {
    SimpleReport report = new SimpleReport("Sales Data for Q1");
    System.out.println(report.generateReportContent());
  }
}

O: Open/Closed Principle (OCP)

The Open/Closed Principle: software should be open for extension but closed for modification. Add new behavior without editing working code.

OCP in Action: Flexible Greeters

Here a new greeter type slots in without touching the Greeter interface or existing classes — extending behavior, not modifying it. That’s OCP.

interface Greeter {
  String greet();
}

class EnglishGreeter implements Greeter {
  @Override
  public String greet() {
    return "Hello!";
  }
}

class SpanishGreeter implements Greeter {
  @Override
  public String greet() {
    return "¡Hola!";
  }
}

public class OCPDemo {
  public static void main(String[] args) {
    Greeter english = new EnglishGreeter();
    Greeter spanish = new SpanishGreeter();
    System.out.println(english.greet());
    System.out.println(spanish.greet());
  }
}

L: Liskov Substitution Principle (LSP)

The Liskov Substitution Principle: a subclass must be usable anywhere its parent is expected, without breaking the program. Subtypes honor the contract.

LSP in Action: Shapes

Any function taking a Shape handles both Rectangle and Circle correctly — they honor the contract. That’s LSP at work.

interface Shape {
  double getArea();
}

class Rectangle implements Shape {
  private double width; 
  private double height;

  public Rectangle(double width, double height) {
    this.width = width;
    this.height = height;
  }

  @Override
  public double getArea() {
    return width * height;
  }
}

class Circle implements Shape {
  private double radius;

  public Circle(double radius) {
    this.radius = radius;
  }

  @Override
  public double getArea() {
    return Math.PI * radius * radius;
  }
}

public class LSPDemo {
  public static void printArea(Shape shape) {
    System.out.println("Area: " + shape.getArea());
  }

  public static void main(String[] args) {
    Shape myRectangle = new Rectangle(5, 4);
    Shape myCircle = new Circle(3);

    printArea(myRectangle);
    printArea(myCircle);
  }
}

I: Interface Segregation Principle (ISP)

The Interface Segregation Principle: don’t force clients to depend on methods they don’t use. Prefer many small, focused interfaces over one fat one.

D: Dependency Inversion Principle (DIP)

The Dependency Inversion Principle: high-level and low-level modules should both depend on abstractions, not concrete details. That’s how you get loose coupling.

Check Your Understanding

Which of the following statements correctly describe the benefits of applying SOLID principles?

Recap: The Power of SOLID

You’ve met all five SOLID principles — single responsibility, open/closed, Liskov, interface segregation, dependency inversion — the toolkit for adaptable software.

Häufig gestellte Fragen

Ist die Lektion „Überblick über die SOLID-Prinzipien“ kostenlos?

Ja — der vollständige Text von „Überblick über die SOLID-Prinzipien“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Clean Architecture & Design Patterns in Practice-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Clean Architecture & Design Patterns in Practice-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Überblick über die SOLID-Prinzipien“?

Erhalten Sie eine Einführung in die fünf SOLID-Prinzipien: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation und Dependency Inversion. Du übst Clean Architecture & Design Patterns in Practice mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Clean Architecture & Design Patterns in Practice zu starten?

Keine Vorkenntnisse erforderlich. Clean Architecture & Design Patterns in Practice auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Überblick über die SOLID-Prinzipien“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Clean Architecture & Design Patterns in Practice-Lektion Code schreiben und ausführen?

Ja. Jede Clean Architecture & Design Patterns in Practice-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Einführung in Clean Code
  2. Überblick über die SOLID-Prinzipien
  3. Der Wert guten Designs
  4. Kohäsion, Kopplung und Trennung von Verantwortlichkeiten
← Zurück zu Clean Architecture & Design Patterns in Practice