Open Closed Principle (OCP): The Open Closed Principle (OCP) states that software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. This means that new functionality can be added without changing the existing code, making the software more maintainable and robust.
Interface Segregation Principle (ISP): The Interface Segregation Principle (ISP) states that clients should not be forced to depend on interfaces they do not use. By creating smaller, cohesive interfaces, this principle helps to prevent a class from implementing unnecessary methods, reducing complexity and improving code readability.
Dependency Inversion Principle (DIP): The Dependency Inversion Principle (DIP) states that high-level modules should not depend on low-level modules. Instead, both should depend on abstractions. By using interfaces or abstract classes to define the dependencies, this principle promotes loose coupling, making the code more flexible, testable, and easier to maintain.
Single Responsibility Principle (SRP): The Single Responsibility Principle (SRP) states that a class should have only one reason to change. By separating concerns and assigning each class a single responsibility, this principle improves code organization, readability, and maintainability.
Liskov Substitution Principle (LSP): The Liskov Substitution Principle (LSP) states that objects of a superclass should be replaceable with objects of its subclasses, without affecting the correctness of the program. This principle ensures that inheritance is used correctly, avoiding unexpected behavior and allowing the code to be extended without breaking existing functionality.
Inversion of Control: Inversion of Control (IoC) is a design principle that refers to the external control of an object's lifecycle, rather than the object itself managing its dependencies and resources. This principle enables loose coupling, promotes modularity, and simplifies testing and maintenance.
Violation in SRP: A violation of the Single Responsibility Principle (SRP) occurs when a class has multiple responsibilities, making it difficult to understand, maintain, and reuse. This measurement helps identify classes that may require refactoring to adhere to the principle, improving code quality and reducing complexity.
Cohesion and Encapsulation: Cohesion refers to the degree to which the elements of a module or class are related to each other. Encapsulation refers to the bundling of related data and behavior into a single entity, such as a class. Measuring cohesion and encapsulation helps assess the design and organization of the code, ensuring high cohesion and strong encapsulation for better maintainability and extensibility.