The document discusses design principles and patterns in software development, emphasizing the importance of a good design architecture to accommodate requirement changes. It introduces the SOLID principles, which are a set of five guidelines aimed at improving software maintainability and adaptability. Each principle focuses on specific aspects of design, such as ensuring single responsibilities for classes and allowing for easy extension without altering existing code.
The document discusses design principles and patterns in software development, emphasizing the importance of a good design architecture to accommodate requirement changes. It introduces the SOLID principles, which are a set of five guidelines aimed at improving software maintainability and adaptability. Each principle focuses on specific aspects of design, such as ensuring single responsibilities for classes and allowing for easy extension without altering existing code.
The designing and development of the software are performed in the design phase of a software development project. When developing the software of the project, generally there are changes in the requirements document that may occur, such as the client adding additional requirements or changing a requirement. These changes could affect the development of the software where there is a need to apply changes on the source codes. When the software architecture has a bad design, it will be hard to apply changes on the project. According to Robert Martin (as cited in oodesign.com), there are three (3) important characteristics of a bad design architecture that should be avoided: Rigidity–The software is hard to change because every applied change will affect many parts of the software. Fragility–When applying changes, unexpected parts of the software breaks. Immobility – The modules of the software are hard to reuse in another software because these cannot be extracted from the current software. To create a good design architecture, various software design principles can be followed. Design principles are a set of guidelines to be followed that helps developers arrange methods and data structures into classes, and how those classes should be interconnected, which can adapt to the changes in requirements without major code rewrites. The SOLID Principles Martin assembled a set of five (5) software design principles, and Michael Feathers arranged these principles into an acronym called SOLID. The SOLID principles of object- oriented design are applied to software development projects to make software easier to change when requirements changes. These are the design principles of the SOLID principles: S: Single Responsibility Principle (SRP) – This is one of the basic principles most developers apply to build robust and maintainable software. This suggests that each software module, class, or interface should have only one (1) reason to change. O: Open-Closed Principle (OCP)– This states that for a software to be easy to change, the software classes must be designed to allow the behavior of those classes to be changed by adding new code rather than changing existing code. L: Liskov Substitution Principle (LSP)–Barbara Liskov introduced this principle which states that the derived classes should be substitutable for their base classes to build a software from interchangeable modules or classes. I: Interface Segregation Principle (ISP)–This principle advises software designers to avoid depending on things that they don’t use. D: Dependency Inversion Principle (DIP) – This principle suggests that flexible software are those with classes that depend on abstract classes or interfaces. Each of these principles can be practiced by any software developer to help them in solving various software development problems. Following these principles help developers to achieve the following: Reduce the complexity of source codes Increase readability, extensibility, and maintenance Reduce accidental errors and implement reusability easily Achieve easier and better software testing. SINGLE RESPONSIBILITY PRINCIPLE The Single Responsibility Principle (SRP) instructs developers to design each module, interface, or class of a software system to have only one (1) responsibility. The software systems are changed to satisfy the needs of the users or actors. Those users are the “reason to change” that the principle is referring to. When requirements change during development, the responsibility of a class also changes. Classes with more than one (1) responsibility should be broken down into smaller classes, each of which should only have a single responsibility and reason to change. SRP does not state that a class should only have one(1)method; rather, a class can have any number of members such as methods and instance variables as long as its members are related to only single responsibility of the class. Example class that violates SRP Figure 1 shows an example of a UML class diagram of Employee class from a payroll application. This class violates the SRP because its methods consist of three (3) responsibilities to three (3) different actors: OPEN-CLOSED PRINCIPLE LISKOV SUBSTITUTION PRINCIPLE INTERFACE SEGREGATION PRINCIPLE DEPENDENCY INVERSION PRINCIPLE