Clean Code Quick Reference
==========================
I. Core Principles
------------------
• DRY (Don’t Repeat Yourself): Avoid repeating code – reuse functions or modules.
• KISS (Keep It Simple, Stupid): Keep your design simple and clear.
• YAGNI (You Aren’t Gonna Need It): Don’t build features you don’t need yet.
• SOLID Principles:
- SRP: Single Responsibility Principle – one reason to change.
- OCP: Open/Closed Principle – open for extension, closed for modification.
- LSP: Liskov Substitution Principle – derived classes must be substitutable.
- ISP: Interface Segregation Principle – don’t force unused methods.
- DIP: Dependency Inversion Principle – depend on abstractions, not details.
II. Design & Structure
----------------------
• Encapsulation: Hide internal details, expose only necessary interfaces.
• Abstraction: Focus on essential behavior, hide complex details.
• Polymorphism: Same interface, different behavior.
• Inheritance: Share common behavior through class hierarchies.
• Composition over Inheritance: Prefer combining objects over deep inheritance.
• Immutability: Objects whose state cannot change after creation.
III. Code Quality & Organization
--------------------------------
• Refactoring: Improve internal structure without changing behavior.
• Code Smells: Signs of poor design (e.g., duplication, long methods).
• Naming Convention: Consistent naming (camelCase, PascalCase).
• Separation of Concerns: Divide code by purpose and responsibility.
• Loose Coupling: Reduce dependencies between modules.
• High Cohesion: Related functionality stays together.
• Testability: Easy to test and verify code.
• Readability: Easy to understand for any developer.
• Maintainability: Easy to modify and extend safely.
IV. Patterns & Architecture
---------------------------
• Design Patterns: Proven solutions (Singleton, Factory, Observer, etc.).
• Repository Pattern: Separate data access from logic.
• Service Layer: Business logic layer outside controllers.
• Dependency Injection (DI): Pass dependencies instead of creating them.
• DTO (Data Transfer Object): Transfer structured data between layers.
• Mapper: Convert data between layers (Model ↔ DTO).
• Controller Fatigue: Overloaded controllers – avoid heavy logic in them.