Software Principles Overview
A collection of fundamental principles and philosophies for designing robust, maintainable, and scalable software.
Table of Contents
SOLID Principles
The foundation of Object-Oriented Design (Uncle Bob).
- SRP (Single Responsibility Principle): A class/module should have one, and only one, reason to change.
- OCP (Open/Closed Principle): Software entities should be open for extension, but closed for modification.
- LSP (Liskov Substitution Principle): Subtypes must be substitutable for their base types without altering correctness.
- ISP (Interface Segregation Principle): Clients should not be forced to depend on interfaces they do not use.
- DIP (Dependency Inversion Principle): High-level modules should not depend on low-level modules. Both should depend on abstractions.
GRASP Principles
General Responsibility Assignment Software Patterns (Larman).
- Information Expert: Assign responsibility to the class with the information.
- Creator: Who creates A? Container of A, recorder of A, user of A.
- Controller: Entry point for a system operation (Facade/Use Case controller).
- Low Coupling: Minimizing dependencies/impact of change.
- High Cohesion: Keeping responsibilities focused and manageable.
- Polymorphism: Handling handling alternatives based on type.
- Pure Fabrication: Artificial class to maintain cohesion/coupling (e.g., Service).
- Indirection: Intermediate object to decouple components.
- Protected Variations: Wrapper around instability/variation points.
General Design Philosophy
Guiding mottos for simple and maintainable code.
- KISS (Keep It Simple, Stupid): Simplicity should be a key goal in design, and unnecessary complexity should be avoided.
- YAGNI (You Aren’t Gonna Need It): Do not add functionality until it is practically necessary.
- DRY (Don’t Repeat Yourself): Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
- SoC (Separation of Concerns): Distinct sections of the computer program should address distinct issues.
- LoD (Law of Demeter): “Principle of Least Knowledge”. A module should not know about the innards of the objects it manipulates.
- Convention Over Configuration: Decrease the number of decisions that a developer using the framework is required to make.
Component & Package Principles
How to organize classes into components/packages (Clean Architecture).
- REP (Release Reuse Equivalency Principle): The granule of reuse is the granule of release.
- CCP (Common Closure Principle): Classes that change together belong together.
- CRP (Common Reuse Principle): Don’t force users of a component to depend on things they don’t need.
- ADP (Acyclic Dependencies Principle): Allow no cycles in the component dependency graph.
- SDP (Stable Dependencies Principle): Depend in the direction of stability.
- SAP (Stable Abstractions Principle): A component should be as abstract as it is stable.
Distributed & System Architecture
Principles for building robust, scalable systems.
- 12-Factor App: A methodology for building software-as-a-service apps.
- REST Constraints: Architectural style for distributed hypermedia systems.
- CAP Theorem: Consistency, Availability, Partition tolerance (Pick two).
- BASE: Basic Availability, Soft state, Eventual consistency.
- Reactive Manifesto: Responsive, Resilient, Elastic, Message Driven.
- CQS: Command Query Separation.
- CQRS: Command Query Responsibility Segregation.
Reliability & Security
Principles for ensuring system stability and safety.
- ACID: Atomicity, Consistency, Isolation, Durability.
- Principle of Least Privilege: A subject should be given only those privileges needed for it to complete its task.
- Defense in Depth: Layering security mechanisms to increase security of the system as a whole.
- Fail Fast: Systems should stop normal operation rather than attempt to continue a possibly flawed process.
Testing Principles
Guidelines for writing effective tests.
- F.I.R.S.T: Fast, Independent, Repeatable, Self-Validating, Timely.