A curated collection of software design pattern implementations developed as part of a university course on Design Patterns.
This repository showcases clean, modular, and extensible solutions to real-world inspired problems, each focusing on specific GoF (Gang of Four) design patterns.
The project is structured as seven independent assignments, each implemented in its own folder and demonstrating one or more design patterns in action. Together, they form a cohesive portfolio suitable for academic evaluation and professional CVs.
Each assignment is contained in its own folder (to be renamed based on the short titles below):
PatternCraft/
│
├── 1-TradePulse/
├── 2-ContactCore/
├── 3-LibraryFlyweight/
├── 4-ChatStateHub/
├── 5-DocuGuard/
├── 6-ApprovalChain/
└── 7-PayFlex/
Stock Market Simulation
Design Patterns Used: Strategy, Observer
Assignment Description:
- Design a simple stock market simulation system that incorporates the following design patterns:
- Strategy Pattern: Implement different trading strategies.
- Observer Pattern: Notify traders when stock prices change.
- Requirements:
- Create a Stock class with name and price attributes.
- Implement a StockMarket class that holds a collection of stocks.
- Design trading strategies using the Strategy pattern (simply print whether the trader buys the given stock. No need to maintain a list of how much is owned).
- LowPriceStrategy: buy when price < 500.
- HighPriceStrategy: buy when price > 1000.
- Implement the Observer pattern to notify traders of price changes.
Contact Management System
Design Patterns Used: DAO, Factory Method, Abstract Factory
Assignment Description:
- Create a contact management system.
- Storing Contacts and Addresses.
- System should not be dependent on how data is stored.
- Create an implementation for storing contacts in memory, or serializing them to file.
- But leave the system open for further extensions to store in other formats.
- Contacts should have:
- id, First name, Last name, email.
- Addresses should have:
- id, Street, City, Post code, contact ID.
- Utilize DAO, Factory Method and Abstract Factory.
- Write demo code utilizing the contact management system, accessing Contacts and Addresses separately, as well as together (getting the address for a contact).
Large-Scale Library Management
Design Patterns Used: Flyweight, Visitor
Assignment Description:
- Develop a system for a large library that manages various types of media items (books, magazines, and DVDs).
- The library could have millions of items, and to conserve memory, you need to use the Flyweight pattern for sharing common attributes.
- Additionally, the library wants to perform different operations on these items without modifying the item classes, using the Visitor pattern.
- Your task is to implement this system using both the Flyweight and Visitor patterns.
- The system should:
- Use Flyweight to share common attributes (e.g., publisher, genre) among media items.
- Implement at least three types of media items: Book, Magazine, and DVD.
- Use the Visitor pattern to implement three operations:
- Calculate lending fee for each item (varies by item type and condition).
- Show catalog entry: display the item (format differs for each item type).
- Search for items of a particular Genre.
- Demonstrate the usage of both patterns in a main method.
State-Aware Chat Application
Design Patterns Used: Mediator, State
Assignment Description:
- Extend the chat room example where the chat application allows users to communicate with each other.
- Users can be in different states, such as "Online", "Away", or "Busy", and they can switch between these states.
- Message behaviour:
- When online: all incoming messages (general chat or private) are immediately displayed by the client.
- When away: all messages received while away are displayed immediately, and also counted. As the user returns to Online, they are told that they missed X number of messages.
- When busy: messages received are not displayed, only once the user returns to online or goes to away.
- The application should use the Mediator pattern to facilitate communication, and the State pattern to manage user states.
- Write demo code to demonstrate all the features.
Secure Document Management
Design Patterns Used: Command, Proxy
Assignment Description:
- Design a document management system for a company.
- The system should allow users to perform operations on documents (such as view, edit, and delete) while also implementing access control and logging.
- Use the Command pattern to encapsulate document operations and the Proxy pattern to add a security layer and logging functionality.
- Requirements:
- Implement commands for the following document operations:
- View document.
- Edit document.
- Delete document.
- Create a command executor that can execute these commands.
- Implement a proxy for the document that:
- Checks user permissions before allowing operations.
- Logs all operations performed on documents.
- Ensure that the system is flexible enough to easily add new document operations in the future.
- Implement commands for the following document operations:
Document Approval Workflow
Design Patterns Used: Chain of Responsibility, Null Object
Assignment Description:
- Create a document approval system for a company.
- The company has different levels of employees (Junior, Senior, Manager, Director) who can approve documents based on their importance level.
- Design the system using the Chain of Responsibility pattern and incorporate the Null Object pattern.
- Requirements:
- Create four levels of approvers: Junior, Senior, Manager, and Director.
- Each document has an importance level from 1 to 5 (1 being least important, 5 being most important).
- Juniors can approve level 1 documents, Seniors can approve up to level 2, Managers up to level 3, and Directors can approve up to level 4.
- If a document can't be approved by any level, it should be handled gracefully without throwing an exception.
- Implement a method to process documents and show the approval chain in action.
Webshop Payment Integration
Design Patterns Used: Factory, Singleton
Assignment Description:
- Webshop needs to integrate multiple third-party payment gateways (with different APIs) to process customer orders.
- Main OrderService needs to process payments without knowing the specific details of which payment gateway is being used.
- Make sure OrderService doesn't create its own dependencies (such as payment processors).
- Payment processors should be instantiated by a factory, which should be a singleton.
This repository demonstrates:
- Practical application of core design patterns.
- Clean separation of concerns.
- Extensible and maintainable system design.
- Readable and well-structured academic code suitable for professional portfolios.
📌 Author: Shihab Muhtasim
📚 Course: Design Patterns
🎓 Program: IPCVAI at PPCU, Budapest, Hungary