Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern to encapsulate common functionality among UI controls

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?

like image 380
Dan Avatar asked Nov 15 '22 10:11

Dan


1 Answers

You may want to take a look at the:

  1. Facade Pattern
  2. Decorator pattern
  3. Observer pattern

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.

like image 177
monksy Avatar answered Dec 22 '22 11:12

monksy