Skip to content

This repository provides a comprehensive implementation and explanation of the SOLID principles using TypeScript.

Notifications You must be signed in to change notification settings

baarayy/SOLID-Principles

Repository files navigation

SOLID Principles

This repository contains my TypeScript examples to illustrate the five SOLID principles of object-oriented design. Each principle is demonstrated in a separate folder:

1. Single Responsibility

This principle states that a class should have only one reason to change. The example demonstrates how to create classes with a single responsibility and avoid violating this principle.

2. Open-Closed

This principle suggests that a class should be open for extension but closed for modification. The example shows how to use abstract classes, interfaces, and design patterns to achieve a system that is easily extensible without modifying existing code.

3. Liskov Substitution

This principle states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. The TypeScript example illustrates how to design classes to adhere to this principle, promoting code reliability and maintainability.

4. Interface Segregation

This principle suggests that a class should not be forced to implement interfaces it does not use. The example shows how to create cohesive and focused interfaces to avoid unnecessary dependencies between classes.

5. Dependency Inversion

This principle emphasizes that high-level modules should not depend on low-level modules but rather both should depend on abstractions. The example demonstrates how to use dependency injection and inversion of control to achieve a flexible and maintainable codebase.