link: Object Oriented Programming
Design Principles
Overview
Design principles are fundamental guidelines that help software developers create high-quality software. They provide a framework for making design decisions that enhance the maintainability, scalability, and robustness of software applications.
Abstract
Good design principles streamline software development processes and ensure that software systems are easier to manage and adapt over time. They serve as the backbone for creating efficient, error-resistant, and adaptable software architectures.
Content
Key Concepts
Effective software design encompasses a set of core principles that guide developers in creating systems that are both functional and maintainable:
Important
- Code reuse: Promotes the use of the same code in different parts of a software system, reducing redundancy and increasing reliability.
- Extensibility: Allows software to be easily extended with new features without significant modifications to existing code.
- Encapsulate What Varies: Encourages developers to isolate components that change frequently, protecting other parts of the system from extensive changes.
- Depend on Abstraction: Suggests relying on abstract classes or interfaces instead of concrete implementations to reduce dependencies and enhance modularity.
- Favor Composition Over Inheritance: Recommends using composition rather than inheritance to achieve code reuse, which provides more flexibility and reduces the dependency hierarchy.
- SOLID Principles: A set of five design principles that contribute to writing clean code that accommodates new features and changes with minimal effort.
- Don’t Repeat Yourself (DRY)
- Keep It Short and Simple (KISS)
- You Ain’t Gonna Need It (YAGNI)
- Law of Demeter (LoD)
- Fault Tolerance
Design Principles vs Design Patterns
Content
Design Principles
Design principles are overarching rules that help developers design better software architectures. They are language-independent and focused on broader aspects of software design:
Important
- Principles Overview: Provides general guidelines and philosophies that can be applied to improve software design and development.
- SOLID Principles: Includes principles like the Single Responsibility Principle (SRP), which advises that a class should have only one reason to change, enhancing the modularity and maintainability of the code.
For instance, SRP is a concept that does not dictate how to implement features in your code but rather serves as a guideline to keep each class focused on a single functionality.
Design Patterns
On the other hand, design patterns are practical, reusable solutions to common problems in software design. They are more specific than design principles and provide a way to solve design issues in particular scenarios:
Important
- Pattern Overview: Offers detailed, reusable solutions for frequently encountered problems in object-oriented software design.
- Examples of Patterns: Patterns such as Singleton, which ensures a class has only one instance and provides a global point of access to it, offer specific implementation guidelines that are universally applicable and tested.
Design patterns are derived from the accumulated experience of skilled software engineers and are embodied in the widely recognized Gang of Four (GoF) patterns, including Abstract Factory, Factory Method, Singleton, and Command, among others.
Link to original