> For the complete documentation index, see [llms.txt](https://huy312100.gitbook.io/software-development/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://huy312100.gitbook.io/software-development/design-pattern/use-cases/real-life-example.md).

# Real-life example

#### Example: E-Commerce Application

Consider an e-commerce application. It might use several patterns as follows:

1. **Factory Method** for creating different types of products.
2. **Singleton** for managing a single instance of a shopping cart.
3. **Observer** for notifying users of price changes or product availability.
4. **Strategy** for implementing various payment methods.
5. **Decorator** for adding features to products dynamically (e.g., gift wrapping).
6. **Facade** for providing a simple interface to the complex operations involved in order processing.
7. **Adapter** for integrating third-party payment gateways.

#### Example: Real-Life Software Project

Let's outline a scenario for a project and the potential design patterns that could be used:

**Project: Content Management System (CMS)**

1. **Factory Method**: For creating different types of user accounts (admin, editor, viewer).
2. **Abstract Factory**: For creating different themes and UI components that need to be consistent across the application.
3. **Singleton**: For managing the application's configuration settings.
4. **Observer**: For notifying subscribers about new content or updates to existing content.
5. **Decorator**: For adding additional features to articles, such as comments, ratings, and tags.
6. **Strategy**: For handling various content formatting options (Markdown, HTML, plain text).
7. **Command**: For implementing undo and redo functionalities for content editing.
8. **Composite**: For managing the hierarchy of UI components or nested content elements.
9. **Facade**: For providing a simplified interface to the complex subsystem of the publishing workflow.
10. **Adapter**: For integrating with external plugins or third-party services.

#### **Financial Trading System**

* **Design Patterns Used**:
  * **Observer**: Notifies traders of market data updates (stock prices, news).
  * **Strategy**: Implements different trading algorithms (algorithmic trading).
  * **Singleton**: Manages a central order book or trade execution system.
  * **Decorator**: Enhances trade objects with additional functionalities (risk management, compliance checks).
* **Example**: A financial trading platform such as Bloomberg or E\*TRADE applies design patterns to handle real-time data feeds, trade execution, risk management, and regulatory compliance.

#### **Enterprise Resource Planning (ERP) System**

* **Design Patterns Used**:
  * **Composite**: Represents hierarchical organizational structures (departments, divisions).
  * **Singleton**: Ensures single instances of critical resources or services.
  * **Factory Method**: Creates instances of business objects (invoices, purchase orders).
  * **Observer**: Notifies stakeholders of system events (inventory updates, financial reports).
* **Example**: SAP or Oracle ERP systems utilize design patterns to streamline business processes, manage resources across departments, handle financial transactions, and generate analytics and reports

#### **Video Streaming Platform**

* **Design Patterns Used**:
  * **Observer**: Notifies users of new video uploads or updates.
  * **Factory Method**: Creates instances of different video types (movies, series, documentaries).
  * **Decorator**: Adds features to videos dynamically (subtitles, quality settings).
  * **Singleton**: Manages streaming sessions and user preferences globally.
  * **Facade**: Provides a simplified interface for users to search, browse, and watch videos.
* **Example**: A video streaming platform like Netflix or YouTube applies design patterns to manage user profiles, content libraries, streaming sessions, recommendation algorithms, and payment transactions efficiently

#### **Online Reservation System**

* **Design Patterns Used**:
  * **Strategy**: Differentiates booking algorithms based on user preferences (e.g., seat selection strategies for airlines).
  * **Factory Method**: Creates reservation objects for various services (e.g., hotel rooms, event tickets).
  * **Observer**: Notifies users of booking confirmations, changes, or cancellations.
  * **Facade**: Provides a simplified interface for users to search, select, and confirm reservations across different services (e.g., flights, hotels, rental cars).
* **Example**: Booking.com or Airbnb use design patterns to manage real-time booking availability, user preferences, payment processing, and customer notifications effectively.

#### **Healthcare Information System**

* **Design Patterns Used**:
  * **Observer**: Updates healthcare providers about patient condition changes or new test results.
  * **Decorator**: Enhances patient records with additional details or medical history updates.
  * **Singleton**: Manages critical resources like patient records or medical equipment availability.
  * **Strategy**: Implements different treatment plans or diagnostic algorithms based on patient symptoms or conditions.
* **Example**: Electronic Medical Record (EMR) systems or hospital management systems apply design patterns to ensure secure data management, efficient patient care workflows, regulatory compliance, and interoperability with medical devices.

#### **Online Learning Platform**

* **Design Patterns Used**:
  * **Observer**: Notifies students of new course materials, assignments, or discussion updates.
  * **Factory Method**: Creates instances of different course types (e.g., lectures, quizzes, assignments).
  * **Decorator**: Enhances learning content with multimedia elements, interactive features, or accessibility options.
  * **Strategy**: Adapts learning paths or assessment methods based on student progress or learning style.
* **Example**: Platforms like Coursera or edX leverage design patterns to manage course enrollment, content delivery, student assessments, peer interactions, and certification processes efficiently.

#### **Social Media Platform**

* **Design Patterns Used**:
  * **Observer**: Notifies users of new posts, comments, or messages.
  * **Decorator**: Enhances posts with multimedia content, tags, or privacy settings.
  * **Singleton**: Manages user sessions, preferences, and global application state.
  * **Facade**: Simplifies interactions for users to create, share, and discover content across different networks or communities.
* **Example**: Facebook, Instagram, or Twitter employ design patterns to handle user profiles, news feeds, real-time updates, privacy controls, advertising campaigns, and analytics tracking effectively.
