This project demonstrates the Factory Method design pattern in Java. The Factory Method pattern provides a way to delegate the instantiation logic to subclasses, allowing for more flexible and reusable code.
To get started with this project, clone the repository and ensure you have Java installed.
- Java Development Kit (JDK) 8 or higher
- Clone the repository:
git clone https://github.com/luanmxz/FactoryMethod.git
- Navigate to the project directory:
cd FactoryMethod
The Factory Method pattern defines an interface for creating an object but allows subclasses to alter the type of objects that will be created. This pattern is particularly useful for cases where the exact type of object might vary.
- ButtonInterface: The common interface for all button types.
- Dialog: Abstract class declaring the factory method.
- HTMLButton: Concrete implementation of
ButtonInterface
for HTML buttons. - HTMLDialog: Concrete implementation of
Dialog
for HTML dialogs. - WindowsButton: Concrete implementation of
ButtonInterface
for Windows buttons. - WindowsDialog: Concrete implementation of
Dialog
for Windows dialogs.
You can run the provided examples to see the Factory Method pattern in action.
To run the test for the Factory Method pattern:
javac FactoryMethodTest.java
java FactoryMethodTest
Contributions are welcome! Please fork the repository and submit pull requests for any improvements or additional patterns you would like to add.
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin feature-branch
) - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.