VR-Vantage 3.1.1 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
10.6 - The Humble Dialog Pattern

Table of Contents

Developers often put a lot of logic code inside their dialog boxes.

This makes it hard to change the logic without changing the dialog box, hard to change the dialog box without changing the logic, and makes it impossible to test the logic outside of the GUI (say in an automated tester).

VR-Vantage uses the Humble Dialog pattern to solve this problem. The Humble Dialog pattern provides a smart, tested logic class, and a minimalistic dialog box class.

The figure illustrates a Logic class that does all the work. Its constructor takes an interface class pointer. The interface is an abstract base class that has methods the logic calls to cause changes in the widget.

vrv_humbledialogpattern.png
The Humble Dialog Pattern

The dialog class implements the interface and creates an instance of the Logic class. The TestObject also implements the interface class, but does not need to have any of the GUI elements.

The following example shows how to use this pattern. Suppose you want to write a dialog box that lets the user convert a position in one coordinate system into another coordinate system.

First, you would write the logic class. It might look something like this:

class ConverterLogic
{
public:
ConverterLogic(ConverterInterface* iface);
// Convert position1 into a new coordinate system and
//store result in position2.
bool getConvertPostion(const Point3d& postion1, Point3d& position2)
{
// do the conversion. Now, position2 has the new point...
// makes a call onto the dialog via the Interface pointer.
myInterface->setPositionWidget(position2);
}
};

The logic depends on the interface class to provide the methods it can call:

class ConverterInterface
{
public:
void setPostionWidget() = 0;
};

The dialog class implements the interface:

class ConverterDialog : public ConverterInterface
{
public:
ConverterDialog()
{
// Create the logic and give it a pointer to this dialog.
myLogic = new ConverterLogic(this);
}
// Make the call to change this dialogs position widget.
void setPositionWidget(const Point3d& position);
protected:
ConverterLogic* myLogic;
};

The dialog creates the logic using itself as the implementation of the interface.

You could write a ConverterTester class to test the ConverterLogic without needing to run an application with a GUI. This is useful for automated testing.

class ConverterTester : public ConverterInterface
{
public:
void setPostionWidget(const Point3d& position)
{
if(position != correctPosition)
{
testFailed = true;
}
}
};

10.6.1 The Humble Dialog Pattern Specification

The Humble Dialog pattern has the following requirements:

[<< The Creator Pattern] [Home] [Top of Page]



Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)