Design & UML
From system architecture to class design
Architectural Design
- Styles: layered, client-server, microservices, event-driven
- Trade-offs: coupling, cohesion, deployability, performance
Layered (ASCII)
UI
└─ Service/API
└─ Domain/Business
└─ Data Access
└─ Database
Quality Attributes
| Attribute | Tactics |
|---|---|
| Performance | Caching, async, pooling |
| Scalability | Horizontal scale, stateless services |
| Reliability | Redundancy, retries, timeouts |
| Security | AuthN/Z, encryption, least privilege |
UML Diagrams
- Use Case, Class, Sequence, Activity/State
- Component and Deployment
Class Diagram (ASCII)
+--------------+ +-------------+
| Order |1 * | OrderItem |
+--------------+--------+-------------+
| id | | id |
| date | | qty |
+--------------+ +-------------+
| total() | | amount() |
+--------------+ +-------------+
Design Principles
- SOLID: SRP, OCP, LSP, ISP, DIP
- DRY, KISS, YAGNI
Example
Use interfaces (DIP) and composition over inheritance to reduce coupling.
Design Patterns
| Category | Pattern | Use |
|---|---|---|
| Creational | Factory | Create objects without exposing concrete classes |
| Structural | Adapter | Convert one interface to another |
| Behavioral | Observer | Publish/subscribe change notifications |
| Behavioral | Strategy | Swap algorithms at runtime |
Quick Revision
- Choose architecture by qualities first.
- Show flows with sequence/activity diagrams.
- Apply SOLID to keep code maintainable.