๐ Week 4 Assignment
Refactoring for Clean Architecture
In this assignment, you will refactor your previous project using:
- Design Patterns
- Layered Architecture
- Clean coding principles
The goal is not to add complexity โ
The goal is to improve structure, clarity, and maintainability.
๐ฏ Objective
Transform your existing console-based application into a modular, extensible system using:
โ
Factory Pattern
โ
Strategy Pattern
โ
DTO Pattern
โ
Layered Architecture
๐ Required Project Structure
Organize your project into packages:
com.yourproject
โ
โโโ controller
โโโ service
โโโ repository
โโโ model
โโโ dto
โโโ factory
โ Functional Requirements
Your application must:
- Create products using a Factory
- Add products to a cart
- Apply discount using Strategy Pattern
- Calculate final price
- Return order summary using DTO
- Follow proper layered flow:
Controller โ Service โ Repository
No layer should skip another layer.
๐งฉ Pattern Requirements
1๏ธโฃ Factory Pattern
- Used to create Product objects
- Client should not use
new Product()directly
2๏ธโฃ Strategy Pattern
- Used for discount calculation
- Implement at least two discount strategies:
- NoDiscount
- SeasonalDiscount (10%)
Switch strategy dynamically.
3๏ธโฃ DTO Pattern
Create an OrderSummaryDTO that includes:
- List of product names
- Total price
- Discount applied
- Final amount
Do NOT expose internal model objects directly.
4๏ธโฃ Layered Architecture
Controller
- Handles user input/output
Service
- Contains business logic
Repository
- Stores products/cart data (can use ArrayList)
๐งช Example Flow
- User selects products
- Controller sends request to Service
- Service calls Repository
- Service applies Discount Strategy
- Service returns DTO to Controller
- Controller prints formatted output
๐ Deliverables
Submit:
- Complete project source code
- Proper package structure
- README explaining:
- Which patterns were used
- Why they were used
- How architecture is organized
๐ง Evaluation Criteria
Your assignment will be evaluated based on:
- Correct use of design patterns
- Clean separation of concerns
- Readability of code
- Logical package organization
- Avoidance of tight coupling
- Code simplicity (no over-engineering)
โ Common Mistakes to Avoid
- Using patterns where unnecessary
- Controller directly accessing Repository
- Making everything Singleton
- Writing large classes with too many responsibilities
- Ignoring naming conventions
๐ Expected Learning Outcome
After completing this assignment, you should be able to:
โ
Write modular Java applications
โ
Structure projects like real-world systems
โ
Reduce coupling between components
โ
Improve maintainability and scalability
๐ฌ Reflection (Mandatory)
Answer the following in a short paragraph:
- What was the most difficult part of refactoring?
- Which pattern improved your design the most?
- What would you improve if given more time?
๐ solutions.md or week-4-questions.md?