๐Ÿ“Œ 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:

  1. Create products using a Factory
  2. Add products to a cart
  3. Apply discount using Strategy Pattern
  4. Calculate final price
  5. Return order summary using DTO
  6. 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

  1. User selects products
  2. Controller sends request to Service
  3. Service calls Repository
  4. Service applies Discount Strategy
  5. Service returns DTO to Controller
  6. 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:

  1. What was the most difficult part of refactoring?
  2. Which pattern improved your design the most?
  3. What would you improve if given more time?

๐Ÿ‘‰ solutions.md or week-4-questions.md?


This site uses Just the Docs, a documentation theme for Jekyll.