-
Notifications
You must be signed in to change notification settings - Fork 0
Design
[to be added]
The SOLID principles are a set of five design principles that help software developers create maintainable, scalable, and flexible systems. These principles are widely regarded as best practices for object-oriented design. The acronym SOLID stands for:
The Single Responsibility Principle (SRP) asserts that a class should be responsible for only one functionality or have only one reason to change. This makes classes easier to maintain, reduces the risk of unintended side effects from future changes, and improves overall readability. In this system, all classes adhere to SRP by focusing on a single responsibility.
For instance, some classes provide specific services or utilities for clients, while others handle distinct operations. This modular design ensures that changes to one functionality do not impact others, maintaining the system's robustness.
The Open/Closed Principle asserts that software should be designed to accommodate new functionality without modifying existing code. This minimizes the risk of changes in one part of the system affecting dependent components, ensuring stability and reducing maintenance overhead. The system adheres to this principle by utilizing predefined interfaces that dictate its behavior. For example, the MarkSchemeLoaderStrategy interface specifies the logic for loading a mark scheme file. To extend the system’s functionality, developers can implement new versions of these interfaces without altering the core system code.
For instance, if support for parsing a JSON-based mark scheme needs to be added alongside YAML support, a JSONMarkSchemeLoader class can be introduced. This approach ensures that the system remains extensible and stable, allowing new features to be integrated seamlessly while preserving the integrity of the existing codebase.
The Liskov Substitution Principle (LSP) states that objects of a superclass should be replaceable with objects of its subclasses without compromising the correctness or functionality of the application. For this to hold, subclass objects must exhibit behavior that aligns with the expectations defined by the superclass, maintaining compatibility and adhering to the same contractual obligations.
In this system, any GradeTemplate subclass can seamlessly substitute a GradeTemplate object without disrupting the program's functionality. This ensures that the code adheres to the LSP, as the program continues to operate as intended regardless of the specific subclass in use.
The Interface Segregation Principle asserts that interfaces should be designed to cater specifically to the needs of individual clients or tasks, ensuring that no client is forced to depend on methods it does not use. By adhering to the principle, software is divided into smaller, more focused, and independent modules, reducing side effects and the frequency of changes. This promotes better maintainability, easier testing, and greater flexibility, as modifications to one interface are less likely to impact unrelated parts of the system.
In this system, no class is forced to implement unused behavior, and the interfaces are clearly separated according to specific responsibilities. This ensures that each class only interacts with the relevant methods, promoting a cleaner, more modular design that is easier to maintain and extend.
The Dependency Inversion Principle (DIP) asserts that high-level modules should not depend on low-level modules. Instead, both should depend on abstractions (e.g., interfaces or abstract classes). Furthermore, abstractions should not depend on details; details should depend on abstractions. This principle promotes loose coupling between components, making the system more flexible and easier to maintain.
In this codebase, no high-level modules depend on low-level modules. Instead, they depend on interfaces, which act as the abstractions between them. This ensures that changes in the low-level module implementation do not affect the high-level module, allowing for easier extensions and modifications while maintaining system stability.