Adapt Don’t Implement

Context

ModelViewController style application programming.

Problems

Adapt Don't ImplementYou have some object, nicely modeled to represent your solution domain. Next, you have to visualize the object (the model) with more than one widget (view/controller). Each widget has its own set of Events, Listeners, and requires the model to implement a widget-specific model interface.

Now, you can start to implement one model interface after the other, which creates two problems:

1) The class becomes cluttered with interfaces

2) You cannot use default, basic or abstract implementations. All listener handling needs to be coded from scratch.

Solutions

Don’t implement all the interfaces at your data model. Instead, design the interface of your data model in a generic, domain-specific way.

Provide the data model with a notification/listener interface, allowing the data model to receive notifications specific to the model.

Use the AdapterPattern to provide widget-specific interfaces. Adapt the model’s get/set methods; including, the model’s listener/notification methods to the ones needed by specific widgets.

The adapter is derived from the default, basic or abstract model implementations that exist for the widgets under discussion, providing a head start for listener and event handling.
The adapters take an instance of the model as argument for their constructors.