You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ The design patterns covered include:
9
9
4.**Iterators** - Custom iterators in a ride-sharing context.
10
10
5.**Decorators** - Visual modifications to digital images using the decorator pattern.
11
11
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.
12
14
13
15
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.
14
16
@@ -20,6 +22,8 @@ Each directory includes fully implemented code to demonstrate these patterns in
**Link to Directory**: [Singleton-Multiton-Factory](Singleton-Multiton-Factory)
137
141
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.
**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
+
138
179
## Summary of Design Patterns and Applications
139
180
140
181
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