This project implements an ordering system for an ice cream parlor, utilizing various Design Patterns to ensure modular, extensible, and easily maintainable code. The goal is to optimize the order flow, from creating and customizing ice cream to managing discounts and tracking order status.
To create a robust system for managing ice cream orders, allowing for:
- Flavor and Type Management: Creation of different ice cream types (popsicles, scoops, milkshakes).
- Customization: Adding toppings and extras to orders.
- Discounts: Application of various discount strategies.
- Tracking: Automatic customer notification regarding order status.
- Optimization: Efficient management of the order queue.
The project was developed with the application of the following GoF (Gang of Four) Design Patterns:
- Strategy
- Purpose: Defines a family of algorithms, encapsulates each one, and makes them interchangeable.
- Application: Used to apply different discount strategies (e.g.,
RegularCustomerDiscount,SeasonalDiscount) to orders, which can be easily swapped without altering the core code.
- Decorator
- Purpose: Attaches additional responsibilities to an object dynamically.
- Application: Allows for ice cream customization through the addition of "toppings" (
ToppingDecorator), such as chocolate (ChocolateTopping), in a flexible manner.
- Observer
- Purpose: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- Application: Ensures automatic notification of customers (
Customer) about updates to their order status, via theOrderNotifier.
- Singleton
- Purpose: Ensures a class has only one instance and provides a global point of access to it.
- Application: Used to manage the order queue (
OrderQueue) for the ice cream parlor, ensuring there's only one centralized queue for processing.
- Factory Method
- Purpose: Defines an interface for creating an object, but lets subclasses decide which class to instantiate.
- Application: The
IceCreamFactoryis responsible for creating different types of ice cream (popsicle, scoop, milkshake) in a standardized way.
- Command
- Purpose: Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
- Application: Order-related actions (e.g.,
PlaceOrderCommand) are encapsulated, facilitating the future implementation of "undo" or "redo" functionalities for an order.
- State
- Purpose: Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.
- Application: Controls and manages the different states of an order (
OrderReceived,OrderPreparing,OrderDelivered) through theOrderContext, allowing for smooth transitions between them.
- Facade
- Purpose: Provides a unified interface to a set of interfaces in a subsystem.
- Application: The
OrderFacadesimplifies the process of managing orders and payments, exposing a simpler interface for interaction with the underlying complex system.
- Repository
- Purpose: Separates domain logic from data access logic, providing an in-memory collection of domain objects.
- Application: The
OrderRepositoryacts as a persistence layer to save and retrieve orders and, in the future, customer history.
- Prerequisites: Make sure you have Java Development Kit (JDK) 8 or higher installed on your machine.
- Clone the Repository: (Assuming the project is in a repository)
git clone https://github.com/0xJotave/IceCreamSystem
cd IceCreamSystem
-
Project Structure: The code is organized into Java packages for better modularity (e.g.,
model,service,repository,observer). -
Compilation and Execution:
- Via IDE (IntelliJ IDEA, Eclipse, VS Code): Import the project as a Maven or Gradle project (if configured) or as a simple Java project. Run the
Mainclass located insrc/org/icecream/app/Main.java - Via Terminal (without IDE):
- Navigate to the root of your project (where the
srcfolder is). - Compile the code:
- Navigate to the root of your project (where the
javac src/org/icecream/**/*.java
- Run the main application:
java -cp src org.icecream.app.Main