I'm brainstorming some ideas around a pattern to use for the following scenario.
I have some 3rd party controls that I want to add common functionality to. Functionality is added by handling several of the the events and doing certain things when the events fire along with adding some private variables to hold some state info between events. I want to reuse the code and functionality so this is what I'd typically do.
Create a class for this functionality and pass in the instance of the control that I want to add the functionality to in the constructor.
Then I can add event handlers to the control in the instance of the class.
Can anyone think of alternative patterns to use in order to create this kind of reusable functionality?
You may want to take a look at the:
The facade pattern will allow for you to encapsulate the behavior of the control under the current class. The decorator pattern will allow for you to be able to create stackable controls. The observer pattern will allow for you to manage events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With