AlgoViz

SOLID in one page

medium 45 min

Five principles for classes that can be changed without fear: single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion.

Watch lesson5:16

Where it shows up

The same pattern appears across everyday software.

  • Active Merchant

    A payment library extracted from Shopify, built around one unified API for dozens of payment gateways with very different APIs inside. Order code does not change for another gateway (O, D). Stripe, Adyen or PayPal each become an adapter.

  • Django storage backends

    A custom storage is a subclass of `Storage` that keeps its methods. Files can live on disk or with a cloud provider while application code stays (L, D).

  • SLF4J

    A facade for several Java logging frameworks. The program logs to the abstraction, and the framework is plugged in at deployment (D).

  • OpenTelemetry

    API packages are kept apart from the SDK, so that libraries can be instrumented without choosing where the data goes (I, D).

  • Kubernetes CRI

    The container runtime interface lets the kubelet use many container runtimes without recompiling the cluster components (O, D).

  • Go's small interfaces

    Effective Go says that interfaces with one or two methods are common, such as io.Writer. A type satisfies them without naming them (I).

  • Python collections.abc

    Container, Iterable, Sized, Sequence and MutableSequence: a function asks for the smallest one it needs (I, L).

  • Java Collection, the compromise

    Some methods are optional operations and may throw UnsupportedOperationException. The contract says so openly, and gives up a check by the compiler (L against I).

  • Spring's container

    Objects state their dependencies through constructor arguments or properties, and the container hands them in. Injection as a service. Whether the rules depend on abstractions is still up to you (D).

  • Python logging

    Loggers, handlers, filters and formatters have one job each, and a new destination is a new handler (S, O).