18 November, 2008

Vain Class

Here is a "pattern" I have employed in a couple of projects of mine, can't still decide if it's worth mentioning as a "pattern" but anyway since I found it usefull and reused it here it is:

Vain Class

Pattern Name and Classification
Vain Class a GUI pattern.

Intent
Simplify User to Objects Interface.

Motivation
Let an Object hold parameters that toggle it's behaviour in an environment, these parameters need to be exposed to the user so he can have control of it's behaviour. A single dashboard/control panel need to be displayed to the user so he can oversee/manage all the objects or in an alternative if no such container exists display a stand alone floating window.

Applicability
These objects can be steps/nodes in a workflow, that need to be controled/parametrized by the user. Objects embeded in a simulation environment (ie 3d world), that the user may control.

Structure

Participants
  • A Dashboard Class (optional).
  • The Vain classes that hold the parameters
  • The Gui framework's control classes
Collaboration
  • The Dashboard Class provides the real estate, and controls the display of each Vain Object.
  • The Vain Objects use the Gui's primitive controls on it's real estate which are responsible for displaying the current status, feeding the user input to it's parameters and optionaly notify the environment for the change. It may embed itself in a Dashboard window or create a standalone window that can float until the user discards it.
  • The Gui's primitive controls are bound directly to each Vain Object parameters, so they execute the Data eXchange directly to the parameters variables.
Consequences
A classes's parameters are only accessible through the gui, shortcuts are taken so code bloat is removed (ie set() get() functions for parameters are not needed). User interaction with the internal control objects is more direct so hopefully reduntant interface layers can be discarded. Distribution of gui code, and more tight coupling to the object that is interfaced.

Implementation:
Each Vain Class contains an abstract virtual method  Wnd & GetWnd(Wnd &parent) that takes in the Dashboards container window and returns the Window class associated with the Vain Class. The Dashboard or the Main window then  needs to call the GetWnd and Show the result.

Hail Deisignia All Hail Pattrenia

No comments: