{"id":22330689,"url":"https://github.com/menathndgd/java-design-patterns-examples","last_synced_at":"2025-03-26T07:09:58.464Z","repository":{"id":258474953,"uuid":"873996946","full_name":"MenathNDGD/Java-Design-Patterns-Examples","owner":"MenathNDGD","description":"This repository contains Java implementations of key design patterns: Singleton, Decorator, and Observer. Each pattern is demonstrated through real-world examples, including a database connection manager, a customizable coffee shop, and a weather monitoring system. Ideal for learning OOP design principles.","archived":false,"fork":false,"pushed_at":"2024-10-17T08:42:24.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T08:33:17.458Z","etag":null,"topics":["code-examples","decorator-pattern","java-design-patterns","observer-pattern","oop","real-world-scenario","singleton-pattern"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MenathNDGD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-17T04:43:02.000Z","updated_at":"2024-10-17T08:42:28.000Z","dependencies_parsed_at":"2024-10-19T07:03:27.860Z","dependency_job_id":null,"html_url":"https://github.com/MenathNDGD/Java-Design-Patterns-Examples","commit_stats":null,"previous_names":["menathndgd/java-design-patterns-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenathNDGD%2FJava-Design-Patterns-Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenathNDGD%2FJava-Design-Patterns-Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenathNDGD%2FJava-Design-Patterns-Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenathNDGD%2FJava-Design-Patterns-Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MenathNDGD","download_url":"https://codeload.github.com/MenathNDGD/Java-Design-Patterns-Examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245605730,"owners_count":20643030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-examples","decorator-pattern","java-design-patterns","observer-pattern","oop","real-world-scenario","singleton-pattern"],"created_at":"2024-12-04T04:07:33.464Z","updated_at":"2025-03-26T07:09:58.442Z","avatar_url":"https://github.com/MenathNDGD.png","language":"Java","readme":"# Java Design Patterns Examples 🚀\n\nWelcome to the **Java Design Patterns Examples** repository! This project demonstrates key design patterns in Java through real-world examples. It is ideal for learning Object-Oriented Programming (OOP) design principles.\n\n## Table of Contents 📚\n\n- [Patterns Implemented](#patterns-implemented)\n- [Singleton Pattern](#singleton-pattern)\n- [Decorator Pattern](#decorator-pattern)\n- [Observer Pattern](#observer-pattern)\n- [Code Examples and Insights](#code-examples-and-insights)\n- [How to Run](#how-to-run)\n- [Contributing](#contributing)\n- [License](#license)\n\n## \u003ca name=\"patterns-implemented\"\u003ePatterns Implemented 🛠️\u003c/a\u003e\n\n1. **Singleton Pattern**: Ensures a class has only one instance and provides a global point of access to it.\n2. **Decorator Pattern**: Allows behavior to be added to individual objects, dynamically, without affecting the behavior of other objects from the same class.\n3. **Observer Pattern**: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.\n\n## \u003ca name=\"singleton-pattern\"\u003eSingleton Pattern 🔒\u003c/a\u003e\n\nThe Singleton pattern is demonstrated through a database connection manager.\n\n- **Class**: [`DatabaseConnection`](Singleton%20Pattern/DatabaseConnection.java)\n- **Example Usage**:\n  ```java\n  DatabaseConnection db1 = DatabaseConnection.getInstance();\n  DatabaseConnection db2 = DatabaseConnection.getInstance();\n  db1.query(\"SELECT * FROM users\");\n  db2.query(\"INSERT INTO users VALUES (1, 'John')\");\n  ```\n\n## \u003ca name=\"decorator-pattern\"\u003eDecorator Pattern 🎨\u003c/a\u003e\n\nThe Decorator pattern is demonstrated through a customizable coffee shop.\n\n- **Classes**: [`SimpleCoffee`](Decorator%20Pattern/SimpleCoffee.class), [`MilkDecorator`](Decorator%20Pattern/MilkDecorator.class), [`SugarDecorator`](Decorator%20Pattern/SugarDecorator.class)\n- **Example Usage**:\n  ```java\n  Coffee coffee = new SimpleCoffee();\n  coffee = new MilkDecorator(coffee);\n  coffee = new SugarDecorator(coffee);\n  System.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n  ```\n\n## \u003ca name=\"observer-pattern\"\u003eObserver Pattern 👀\u003c/a\u003e\n\nThe Observer pattern is demonstrated through a weather monitoring system.\n\n- **Classes**: [`WeatherStation`](Observer%20Pattern/WeatherStation.class), [`CurrentConditionsDisplay`](Observer%20Pattern/CurrentConditionsDisplay.class), [`StatisticsDisplay`](Observer%20Pattern/StatisticsDisplay.class)\n- **Example Usage**:\n  ```java\n  WeatherStation weatherStation = new WeatherStation();\n  weatherStation.registerObserver(new CurrentConditionsDisplay());\n  weatherStation.registerObserver(new StatisticsDisplay());\n  weatherStation.setTemperature(80);\n  ```\n\n## \u003ca name=\"code-examples-and-insights\"\u003eCode Examples and Insights 🧠\u003c/a\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eSingleton Pattern Overview 🔒🌐\u003c/code\u003e\u003c/summary\u003e\n\n### Introduction 🌟🧩\n\nThe Singleton Pattern ensures that a class has only one instance and provides a global point of access to that instance. This pattern is useful when exactly one object is needed to coordinate actions across the system.\n\n### Scenario: Database Connection 💻🔗\n\nIn many applications, you need to ensure that only one instance of a database connection is created to prevent resource conflicts and manage resources efficiently. The Singleton pattern ensures that there is only one instance of a class and provides a global point of access to it.\n\n### Code Explanation 📜💻\n\n```java\nprivate static DatabaseConnection instance;\n```\n\n- This variable holds the single instance of the class.\n- Being `static` means it belongs to the class, not to any specific object of the class.\n\n```java\nprivate DatabaseConnection() {\n    System.out.println(\"Database Connection established\");\n}\n```\n\n- The constructor is private, preventing other classes from instantiating the `DatabaseConnection` class directly.\n- It ensures that the only way to get an instance of this class is through the `getInstance` method.\n\n```java\npublic static DatabaseConnection getInstance() {\n    if (instance == null) {\n        instance = new DatabaseConnection();\n    }\n    return instance;\n}\n```\n\n- This method returns the single instance of the class.\n- If the `instance` is `null` (meaning it hasn't been created yet), it creates a new instance.\n- Subsequent calls to `getInstance` return the already created instance, ensuring there's only one instance.\n\n```java\npublic void query(String sql) {\n    System.out.println(\"Executing query: \" + sql);\n}\n```\n\n- This method simulates executing a database query.\n- It prints out the SQL query string provided as an argument.\n\n```java\nDatabaseConnection db1 = DatabaseConnection.getInstance();\nDatabaseConnection db2 = DatabaseConnection.getInstance();\n```\n\n- Both `db1` and `db2` are references to the same instance of `DatabaseConnection`.\n- The `getInstance` method ensures that the same instance is returned both times.\n\n```java\ndb1.query(\"SELECT * FROM users\");\ndb2.query(\"INSERT INTO users VALUES (1, 'John')\");\n```\n\n- The `query` method is called on both `db1` and `db2`.\n- Since `db1` and `db2` refer to the same instance, these calls operate on the same object.\n\n```java\nSystem.out.println(db1 == db2);\n```\n\n- This prints `true` because `db1` and `db2` are references to the same instance.\n\n### Output Explanation 🖥️🔍\n\nWhen running the `Main` class, the final output will be:\n\n```java\nDatabase Connection established\nExecuting query: SELECT * FROM users\nExecuting query: INSERT INTO users VALUES (1, 'John')\ntrue\n```\n\n- **Database Connection established** is printed once when the instance is first created by `DatabaseConnection.getInstance()`.\n- **Executing query: SELECT \\* FROM users** is printed after called the `db1.query(\"SELECT * FROM users\")`.\n- **Executing query: INSERT INTO users VALUES (1, 'John')** is printed when `db2.query(\"INSERT INTO users VALUES (1, 'John')\")` is called.\n- **true** is printed when `System.out.println(db1 == db2)` is executed, confirming that both references point to the same instance.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eDecorator Pattern Overview 🎨✨\u003c/code\u003e\u003c/summary\u003e\n\n### Introduction 🌟🧩\n\nThe Decorator Pattern allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class. This pattern is typically used to extend the functionalities of classes in a flexible and reusable way.\n\n### Scenario: Coffee Shop with Different Add-Ons ☕🍰\n\nIn a coffee shop, you can order a basic coffee and add various add-ons like milk or sugar. The Decorator pattern allows you to add behavior to objects dynamically.\n\n### Code Explanation 📜💻\n\n**_`Coffee Interface`_** defines the structure that all coffee types (both base and decorated) must follow.\n\n```java\ninterface Coffee {\n    String getDescription();\n    double getCost();\n}\n```\n\n- The `getDescription()` method returns a description of the coffee.\n- It implemented by both base and decorator classes.\n- The `getCost()` method returns the cost of the coffee.\n- It also implemented by both base and decorator classes.\n\n**_`SimpleCoffee Class`_** represents a basic coffee without any decorations.\n\n```java\nclass SimpleCoffee implements Coffee {\n    @Override\n    public String getDescription() {\n        return \"Simple Coffee\";\n    }\n\n    @Override\n    public double getCost() {\n        return 5.0;\n    }\n}\n```\n\n- The `getDescription()` method returns **Simple Coffee**.\n- The `getCost()` Method returns a base cost of **5.0**.\n\n**_`CoffeeDecorator Abstract Class`_** implements the `Coffee` interface and serves as the base class for all coffee decorators.\n\n```java\nabstract class CoffeeDecorator implements Coffee {\n    protected Coffee decoratedCoffee;\n\n    public CoffeeDecorator(Coffee coffee) {\n        this.decoratedCoffee = coffee;\n    }\n\n    public String getDescription() {\n        return decoratedCoffee.getDescription();\n    }\n\n    public double getCost() {\n        return decoratedCoffee.getCost();\n    }\n}\n```\n\n- The `decoratedCoffee` field holds the reference to the coffee object being decorated.\n- The constructor initializes the `decoratedCoffee` with the given `coffee`.\n- The `getDescription()` method returns the description of the decorated coffee.\n- The `getCost()` method returns the cost of the decorated coffee.\n\n**_`MilkDecorator Class`_** adds milk to the coffee, extending the `CoffeeDecorator`.\n\n```java\nclass MilkDecorator extends CoffeeDecorator {\n    public MilkDecorator(Coffee coffee) {\n        super(coffee);\n    }\n\n    @Override\n    public String getDescription() {\n        return decoratedCoffee.getDescription() + \" + Milk\";\n    }\n\n    @Override\n    public double getCost() {\n        return decoratedCoffee.getCost() + 1.5;\n    }\n}\n```\n\n- The constructor passes the coffee to be decorated to the `CoffeeDecorator` constructor.\n- The `getDescription()` method appends **+ Milk** to the existing description.\n- The `getCost()` method adds **1.5** to the existing cost.\n\n**_`SugarDecorator Class`_** adds sugar to the coffee, extending the `CoffeeDecorator`.\n\n```java\nclass SugarDecorator extends CoffeeDecorator {\n    public SugarDecorator(Coffee coffee) {\n        super(coffee);\n    }\n\n    @Override\n    public String getDescription() {\n        return decoratedCoffee.getDescription() + \" + Sugar\";\n    }\n\n    @Override\n    public double getCost() {\n        return decoratedCoffee.getCost() + 0.5;\n    }\n}\n```\n\n- The constructor passes the coffee to be decorated to the `CoffeeDecorator` constructor.\n- The `getDescription()` method appends **+ Sugar** to the existing description.\n- The `getCost()` method adds **0.5** to the existing cost.\n\n**_`Main Class`_** demonstrates the use of the decorators to add features to the base coffee.\n\n```java\npublic class Main {\n    public static void main(String[] args) {\n        Coffee coffee = new SimpleCoffee();\n        System.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n\n        coffee = new MilkDecorator(coffee);\n        System.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n\n        coffee = new SugarDecorator(coffee);\n        System.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n    }\n}\n```\n\n**`Creating a Simple Coffee:`**\n\n```java\n   Coffee coffee = new SimpleCoffee();\n   System.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n```\n\n- This creates a `SimpleCoffee` instance.\n- It prints the description and cost: **Simple Coffee $5.0**.\n\n**`Adding Milk to Coffee:`**\n\n```java\n   coffee = new MilkDecorator(coffee);\n   System.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n```\n\n- This decorates the `coffee` with `MilkDecorator`.\n- It prints the new description and cost: **Simple Coffee + Milk $6.5**.\n\n**`Adding Sugar to Coffee:`**\n\n```java\ncoffee = new SugarDecorator(coffee);\nSystem.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n```\n\n- This further decorates the `coffee` with `SugarDecorator`.\n- It prints the new description and cost: **Simple Coffee + Milk + Sugar $7.0**.\n\n### Output Explanation 🖥️🔍\n\nThe Final Output generated as follows:\n\n```java\nSimple Coffee $5.0\nSimple Coffee + Milk $6.5\nSimple Coffee + Milk + Sugar $7.0\n```\n\nWhen the `Main` class is executed, it follows these steps to generate the output:\n\n**`1. Creating a Simple Coffee:`**\n\n```java\nCoffee coffee = new SimpleCoffee();\nSystem.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n```\n\n- A `SimpleCoffee` instance is created.\n- The `getDescription()` method of `SimpleCoffee` returns **Simple Coffee**.\n- The `getCost()` method of Simpl`eCoffee returns **5.0**.\n- The output is: **Simple Coffee $5.0**.\n\n**`2. Adding Milk to Coffee:`**\n\n```java\ncoffee = new MilkDecorator(coffee);\nSystem.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n```\n\n- The `SimpleCoffee` instance is decorated with `MilkDecorator`.\n- The `getDescription()` method of `MilkDecorator` calls the `getDescription()` method of the decorated coffee (which is `SimpleCoffee`) and appends **+ Milk**.\n- The` decoratedCoffee.getDescription()` returns **Simple Coffee**.\n- Then the final description is **Simple Coffee + Milk**.\n- The `getCost()` method of `MilkDecorator` calls the `getCost()` method of the decorated coffee (which is `SimpleCoffee`) and adds **1.5**.\n- In this case, the `decoratedCoffee.getCost()` returns **5.0**.\n- After that, the final cost is **5.0 + 1.5 = 6.5**.\n- Then the output is: **Simple Coffee + Milk $6.5**.\n\n**`3. Adding Sugar to Coffee:`**\n\n```java\ncoffee = new SugarDecorator(coffee);\nSystem.out.println(coffee.getDescription() + \" $\" + coffee.getCost());\n```\n\n- The `MilkDecorator` instance (which already decorates `SimpleCoffee`) is further decorated with `SugarDecorator`.\n- The `getDescription()` method of `SugarDecorator` calls the `getDescription()` method of the decorated coffee (which is `MilkDecorator`) and appends **+ Sugar**.\n- In here the `decoratedCoffee.getDescription()` (which is `MilkDecorator.getDescription()`) returns **Simple Coffee + Milk**.\n- So the final description is **Simple Coffee + Milk + Sugar**.\n- After that, the `getCost()` method of `SugarDecorator` calls the `getCost()` method of the decorated coffee (which is `MilkDecorator`) and adds **0.5**.\n- In that case, the `decoratedCoffee.getCost()` (which is `MilkDecorator.getCost()`) returns **6.5**.\n- So the, final cost is **6.5 + 0.5 = 7.0**.\n- Finally, the output is: **Simple Coffee + Milk + Sugar $7.0**.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eObserver Pattern Overview 👀📡\u003c/code\u003e\u003c/summary\u003e\n\n### Introduction 🌟🧩\n\nThe Observer pattern allows you to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.\n\n### Scenario: A Weather Station that Monitors Temperature 🌤️🌡️\n\nImagine a weather station that monitors temperature and updates multiple displays whenever the temperature changes.\n\n### Code Explanation 📜💻\n\n**_`WeatherSubject Interface`_** defines the methods that any subject (in this case, a weather station) must implement to allow observers to register, unregister, and be notified of changes.\n\n```java\ninterface WeatherSubject {\n    void registerObserver(WeatherObserver observer);\n    void removeObserver(WeatherObserver observer);\n    void notifyObservers();\n}\n```\n\n- The `registerObserver()` method adds an observer to the list of observers.\n- The `removeObserver()` method removes an observer from the list of observers.\n- The `notifyObservers()` method notifies all registered observers of a change.\n\n**_`WeatherStation Class`_** implements the `WeatherSubject` interface and maintains a list of observers. It also holds the temperature data and notifies observers when the temperature changes.\n\n```java\nclass WeatherStation implements WeatherSubject {\n    private List\u003cWeatherObserver\u003e observers;\n    private float temperature;\n\n    public WeatherStation() {\n        this.observers = new ArrayList\u003c\u003e();\n    }\n\n    @Override\n    public void registerObserver(WeatherObserver observer) {\n        observers.add(observer);\n    }\n\n    @Override\n    public void removeObserver(WeatherObserver observer) {\n        observers.remove(observer);\n    }\n\n    @Override\n    public void notifyObservers() {\n        for (WeatherObserver observer : observers) {\n            observer.update(temperature);\n        }\n    }\n\n    public void setTemperature(float temperature) {\n        this.temperature = temperature;\n        notifyObservers();\n    }\n}\n```\n\n- The `observers` field is a list to keep track of registered observers.\n- The `temperature` field shows the current temperature.\n- The `registerObserver()` method adds an `observer` to the list.\n- The `removeObserver()` method removes an `observer` from the list.\n- The `notifyObservers()` method calls the `update()` method on each registered `observer`, passing the current `temperature`.\n- The `setTemperature()` method sets the temp`erature and calls `notifyObservers()` method to update all observers.\n\n**_`WeatherObserver Interface`_** defines the `update()` method that observers must implement to get updates from the subject.\n\n```java\ninterface WeatherObserver {\n    void update(float temperature);\n}\n```\n\n- The `update()` method takes the new `temperature` as an argument and updates the observer.\n\n**_`CurrentConditionsDisplay Class`_** implements the `WeatherObserver` interface and displays the current `temperature`.\n\n```java\nclass CurrentConditionsDisplay implements WeatherObserver {\n    @Override\n    public void update(float temperature) {\n        System.out.println(\"Current conditions: \" + temperature + \"F degrees\");\n    }\n}\n```\n\n- The `update()` method prints the current `temperature` to the console.\n\n**_`StatisticsDisplay Class`_** implements the `WeatherObserver` interface and maintains statistics about the `temperature` (_*average, maximum, and minimum*_).\n\n```java\nclass StatisticsDisplay implements WeatherObserver {\n    private float maxTemp = 0.0f;\n    private float minTemp = 200;\n    private float tempSum = 0.0f;\n    private int numReadings;\n\n    @Override\n    public void update(float temperature) {\n        tempSum += temperature;\n        numReadings++;\n\n        if (temperature \u003e maxTemp) {\n            maxTemp = temperature;\n        }\n\n        if (temperature \u003c minTemp) {\n            minTemp = temperature;\n        }\n\n        display();\n    }\n\n    public void display() {\n        System.out.println(\"Avg/Max/Min temperature = \" + (tempSum / numReadings)\n            + \"/\" + maxTemp + \"/\" + minTemp);\n    }\n}\n```\n\n- The following is how the fields are shown in this instance:\n  - `maxTemp`: Stores the maximum recorded temperature.\n  - `minTemp`: Stores the minimum recorded temperature.\n  - `tempSum`: Stores the sum of all recorded temperatures.\n  - `numReadings`: Counts the number of temperature readings.\n- The `update()` method updates the statistics with the new `temperature` and calls display.\n- The `display()` method prints the _*average, maximum, and minimum*_ temperatures to the console.\n\n**_`Main Class`_** demonstrates the Observer Pattern by creating a `WeatherStation`, registering observers, and changing the temperature.\n\n```java\npublic class Main {\n    public static void main(String[] args) {\n        WeatherStation weatherStation = new WeatherStation();\n\n        CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay();\n        StatisticsDisplay statisticsDisplay = new StatisticsDisplay();\n\n        weatherStation.registerObserver(currentDisplay);\n        weatherStation.registerObserver(statisticsDisplay);\n\n        weatherStation.setTemperature(80);\n        weatherStation.setTemperature(82);\n        weatherStation.setTemperature(78);\n    }\n}\n```\n\n- Creating the WeatherStation:\n\n  - This creates an instance of `WeatherStation`.\n\n    ```java\n    WeatherStation weatherStation = new WeatherStation();\n    ```\n\n- Creating the Observers:\n\n  - This creates instances of `CurrentConditionsDisplay` and `StatisticsDisplay`.\n\n    ```java\n    CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay();\n    StatisticsDisplay statisticsDisplay = new StatisticsDisplay();\n    ```\n\n- Registering the Observers:\n\n  - This registers the observers with the `WeatherStation`.\n\n    ```java\n    weatherStation.registerObserver(currentDisplay);\n    weatherStation.registerObserver(statisticsDisplay);\n    ```\n\n- Setting the Temperature:\n\n  - This changes the temperature, which triggers the `notifyObservers()` method to update all registered observers.\n\n    ```java\n    weatherStation.setTemperature(80);\n    weatherStation.setTemperature(82);\n    weatherStation.setTemperature(78);\n    ```\n\n### Output Explanation 🖥️🔍\n\nThe Final output is generated as follows:\n\n```java\nCurrent conditions: 80.0F degrees\nAvg/Max/Min temperature = 80.0/80.0/80.0\nCurrent conditions: 82.0F degrees\nAvg/Max/Min temperature = 81.0/82.0/80.0\nCurrent conditions: 78.0F degrees\nAvg/Max/Min temperature = 80.0/82.0/78.0\n```\n\nWhen the `Main` class is executed, it follows these steps to generate the output:\n\n**`1. Setting the temperature to 80:`**\n\n- The `CurrentConditionsDisplay` prints: **Current conditions: 80.0F degrees**.\n- The `StatisticsDisplay` updates its statistics as:\n  - Average: _*801=80.0\\frac{80}{1} = 80.0180=80.0*_\n  - Maximum: _*80.0*_\n  - Minimum: _*80.0*_\n  - Prints: **Avg/Max/Min temperature = 80.0/80.0/80.0**\n\n**`2. Setting the temperature to 82:`**\n\n- The `CurrentConditionsDisplay` prints: C**urrent conditions: 82.0F degrees**.\n- The `StatisticsDisplay` updates its statistics as:\n  - Average: _*80+822=81.0\\frac{80 + 82}{2} = 81.0280+82=81.0*_\n  - Maximum: _*82.0*_\n  - Minimum: _*80.0*_\n  - Prints: **Avg/Max/Min temperature = 81.0/82.0/80.0**\n\n**`3. Setting the temperature to 78:`**\n\n- The `CurrentConditionsDisplay` prints: **Current conditions: 78.0F degrees**.\n- The `StatisticsDisplay` updates its statistics as:\n  - Average: _*80+82+783≈80.0\\frac{80 + 82 + 78}{3} \\approx 80.0380+82+78≈80.0*_\n  - Maximum: _*82.0*_\n  - Minimum: _*78.0*_\n  - Prints: **Avg/Max/Min temperature = 80.0/82.0/78.0**\n\n\u003c/details\u003e\n\n## \u003ca name=\"how-to-run\"\u003eHow to Run 🏃‍♂️\u003c/a\u003e\n\n1. Clone the repository:\n   ```sh\n   git clone https://github.com/MenathNDGD/Java-Design-Patterns-Examples.git\n   ```\n2. Navigate to the desired pattern directory:\n   ```sh\n   cd \"Singleton Pattern\"  # or \"Decorator Pattern\", \"Observer Pattern\"\n   ```\n3. Compile and run the `Main.java` file:\n   ```sh\n   javac Main.java\n   java Main\n   ```\n\n## \u003ca name=\"contributing\"\u003eContributing 🤝\u003c/a\u003e\n\nContributions are welcome! Please fork this repository and submit a pull request for any enhancements or bug fixes.\n\n## \u003ca name=\"license\"\u003eLicense 📄\u003c/a\u003e\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenathndgd%2Fjava-design-patterns-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmenathndgd%2Fjava-design-patterns-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenathndgd%2Fjava-design-patterns-examples/lists"}