To build good designs in C, everyone should follow SOLID design principles. These five design principles were described in Bob Martin’s book (Agile Software Development, Principles, Patterns, and Practices). SOLID stands for:

S - Single Responsibility Principle
O - Open Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D - Dependency Inversion Principle

Single Responsibility Principle


The Single Responsibility Principle (SRP) states that a module should have a single responsibility — it should do one thing, and it should have a single reason to change.

Open Closed Principle


A module should be “open for extension but closed for modification.” Let’s take a metaphor:

A USB port can be extended (you can plug any compliant USB devices into the port) but does not need to be modified to accept a new device. So, a computer that has a USB port is open for extension but closed for modification for compliant USB devices.

Liskov Substitution Principle


LSP says that client modules should not care about which kind of server modules they are working with. Modules with the same interface should be substitutable without any special knowledge in the calling code.

Interface Segregation Principle


The Interface Segregation Principle (ISP) suggests that client modules should not depend on fat interfaces. Interfaces should be tailored to the client’s needs.

Dependency Inversion Principle


In the Dependency Inversion Principle (DIP), Bob Martin tells us that high-level modules shouldn’t depend on low-level modules. Both should depend on abstractions. He also says that abstractions should not depend on the details. Details should depend on abstractions. We can break dependencies with abstractions and interfaces. We often implement DIP In C by using a function pointer to break an unwanted direct dependency.