SOLID Principles

Five design principles for writing maintainable object-oriented code.

The data

0

Principle
S - Single Responsibility
Description
A class should have only one reason to change.
Example
Separate UserAuth from UserProfile.

1

Principle
O - Open/Closed
Description
Open for extension, closed for modification.
Example
Add new payment types without changing existing processor.

2

Principle
L - Liskov Substitution
Description
Subtypes must be substitutable for their base types.
Example
A Square should not extend Rectangle if width=height invariant breaks.

3

Principle
I - Interface Segregation
Description
Prefer many small client-specific interfaces over one large interface.
Example
Separate Printer and Scanner interfaces.

4

Principle
D - Dependency Inversion
Description
Depend on abstractions, not concrete implementations.
Example
Controller depends on ILogger interface, not FileLogger.

Fetch the same bytes

The static files are identical to what the API returns, but with no rate limit and no server round trip. Use the API when you want a query and a content type; use the files when you want to cache one document.

curl "https://yjtoon.com/api/dataset/solid-principles?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/solid-principles.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • design-patterns
  • solid
  • oop
  • software-engineering