Skip to content

Commit 23f5c0a

Browse files
committed
Update: Added design patterns
1 parent cad27a0 commit 23f5c0a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The design patterns covered include:
99
4. **Iterators** - Custom iterators in a ride-sharing context.
1010
5. **Decorators** - Visual modifications to digital images using the decorator pattern.
1111
6. **Singleton, Multiton, and Factory Method** - Designing a pizza ordering system with creational patterns.
12+
7. **Observer** - Event-driven store notifications for customers.
13+
8. **Model-View-Controller (MVC)** - Building a simple 2048 game with MVC architecture.
1214

1315
Each directory includes fully implemented code to demonstrate these patterns in realistic scenarios. Below is a comprehensive breakdown of each directory, detailing the design patterns, core components, and practical applications.
1416

@@ -20,6 +22,8 @@ Each directory includes fully implemented code to demonstrate these patterns in
2022
- [`Iterators` Directory](#4-iterators-directory)
2123
- [`Decorators` Directory](#5-decorators-directory)
2224
- [`Singleton-Multiton-Factory` Directory](#6-singleton-multiton-factory-directory)
25+
- [`Observers` Directory](#7-observers-directory)
26+
- [`Model-View-Controller` Directory](#8-model-view-controller-directory)
2327
- [Summary of Design Patterns and Applications](#summary-of-design-patterns-and-applications)
2428
- [Build Tool](#build-tool)
2529
- [Additional Resources](#additional-resources)
@@ -135,6 +139,43 @@ The `Singleton-Multiton-Factory` directory showcases creational design patterns
135139

136140
**Link to Directory**: [Singleton-Multiton-Factory](Singleton-Multiton-Factory)
137141

142+
## 7. `Observers` Directory
143+
144+
**Pattern**: **Observer Design Pattern**
145+
146+
**Context**: Implementing a store with events like discounts and promotions.
147+
148+
The `Observers` directory explores the observer design pattern in the context of a store that notifies customers of order status changes and promotions. By defining observers like **Customer** and **Receipt** that listen for events from the **Store**, this directory demonstrates how to implement event-driven systems with decoupled components.
149+
150+
**Components**:
151+
- **`Customer`**: Represents a customer placing an order.
152+
- **`Store`**: Manages customer orders and notifies observers of order status changes.
153+
- **`Product`**: Represents a pizza product with details like name, price, and ingredients.
154+
- **`Receipt`**: Contains order details and serves as a receipt for customers.
155+
- **`ReceiptItem`**: Represents an item in the order receipt.
156+
- **`SaleSpawner`**: Simulates sales events like discounts and promotions.
157+
158+
**Key Insights**: The observer pattern decouples event producers (subjects) from consumers (observers), allowing for flexible, scalable systems where components can react to changes without direct dependencies. This directory illustrates how to implement event-driven architectures in Java applications.
159+
160+
**Link to Directory**: [Observers](Observers)
161+
162+
## 8. `Model-View-Controller` Directory
163+
164+
**Pattern**: **Model-View-Controller (MVC) Design Pattern**
165+
166+
**Context**: Building a simple 2048 game with MVC architecture.
167+
168+
The `Model-View-Controller` directory demonstrates the MVC design pattern in a game development context. By separating the game logic (model), user interface (view), and user input (controller), this directory showcases how to create modular, maintainable applications with clear separation of concerns.
169+
170+
**Components**:
171+
- **Model (Game2048)**: Manages the game state, rules, and logic.
172+
- **View (Main)**: Renders the game interface and updates the display.
173+
- **Controller (GameController)**: Handles user input and updates the model and view.
174+
175+
**Key Insights**: The MVC pattern divides the game into distinct components, making it easier to manage, test, and extend. By separating concerns and defining clear interactions between components, this directory highlights the benefits of using the MVC pattern in software development.
176+
177+
**Link to Directory**: [Model-View-Controller](Model-View-Controllers)
178+
138179
## Summary of Design Patterns and Applications
139180

140181
This repository provides a practical guide to core design patterns, each applied in real-world contexts to solve common software challenges. Here’s a quick recap of each pattern’s application:

0 commit comments

Comments
 (0)