java-design-patterns
java-design-patterns copied to clipboard
Plugin pattern
Description
The Plugin design pattern allows a software application to support extension through third-party plugins, providing flexibility and scalability. This pattern is particularly useful for applications requiring dynamic and interchangeable components.
Main Elements of the Plugin Design Pattern:
- Plugin Interface: Defines the methods that plugins must implement.
- Concrete Plugins: Implementations of the plugin interface, providing specific functionality.
- Plugin Manager: Responsible for loading, initializing, and managing the lifecycle of plugins.
- Application Core: The main application that uses the plugin manager to interact with plugins.
References:
Acceptance Criteria:
- A Plugin Interface is defined with necessary methods that plugins must implement.
- At least two Concrete Plugin implementations are created, showcasing different functionalities.
- A Plugin Manager class is implemented to handle loading, initializing, and managing the plugins.
- Demonstration of the pattern in a sample application, showing dynamic loading and usage of plugins.
Hello I am ready to tackle this issue. Is there any information I need to read to understand this issue?
@skylermj-252
This pattern is described in Patterns of Enterprise Application Architecture book.
Brief description about the pattern:
- Separated Interface: Some behaviors implementation must be chosen dynamically based on runtime environment. Different environments include Unit Testing, Stress Testing, IoT, Production. Ex of such a requirement is ID generator, in unit testing environment in memory counter based solution should be chosen and in production DB based counter must be chosen.
- Dynamic linking: A plugin implementation is not known during compile time. The actual implementation is chosen based on configuration at runtime, and the class is loaded using reflection. The configuration can be a text file containing full path of plugin class.
- Reconfiguration: Reconfiguration will not require rebuild, as we have them loaded dynamically. I am thinking about a valid use case for this. I will comment as soon as I find an appropriate use case.
Random thoughts on reconfiguration: Java does not allow reloading same class. So I guess reconfiguration means switching from one implementation to other. Like switching from In Memory Counter implementation to DB based counter.
The best implementation approach for this pattern is to use annotations, reflection and dynamic binding in java, and Abstract Factory combined with Strategy pattern so as to give the desired flexibility. Although i am really busy presently, but i will love to render my assistance in any way.
Cheers.
On Fri, Feb 12, 2016 at 11:13 AM, Narendra Pathai [email protected] wrote:
Random thoughts on reconfiguration: Java does not allow reloading same class. So I guess reconfiguration means switching from one implementation to other. Like switching from In Memory Counter implementation to DB based counter.
— Reply to this email directly or view it on GitHub https://github.com/iluwatar/java-design-patterns/issues/351#issuecomment-183261058 .
This issue is free for taking again.
Here are some guidelines http://stackoverflow.com/questions/465099/best-way-to-build-a-plugin-system-with-java
Hi, I see that there is a commit to this issue already but it is still open.
What are the next steps here - Work on existing commit from @npathai or write the solution from scratch?
Can the new person decide what is the right next step?
@abhi-agr you can write the implementation from scratch or utilize @npathai's solution if you wish. Will you work on this?
I am planning to work on this. But I think I need to compare different strategies - OSGI and JPF to find out the better implementation.
Let me come up with a design and later I can move to implementation
Ok @abhi-agr
Issue free again
please check it.
@jasciiz are you still working on this?
This issue is free for taking again.
hi, can I work on this issue?
Yes @lkpengcs, go ahead
@lkpengcs are you working on this?
Sorry, I am a little busy these days and cannot work on this.
May I try to implemented this issue?
Yes @Kaiyan1Zhang
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.