Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2004-12-30 16:05:18


On the subject of GUI object hierarchies, I wanted to bring to everyone's
attention the Boost Interfaces Library (BIL) currently being developed by
Jonathan Turkanis which could be an excellent tool for building a flexible
and efficient GUI library. There is a brief introduction to the library on
the Boost wiki (
http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Boost.Interfaces )

The BIL library, provides a mechanism for non-intrusive structural
subtyping. In other words any object can be used polymorphically if it
provides function signatures which match those of the interface type. The
advantages are that it eliminates the overhead of virtual tables in the
objects. Also dynamic function dispatch only occurs when it is needed (i.e.
through an interface reference). Most importantly the BIL removes the
requirement of inheritance for polymorphism.

The code for declaring the interfaces would look like this:

BOOST_IDL_BEGIN(ILabel)
  BOOST_IDL_CONST_FN0(GetText, string)
  BOOST_IDL_CONST_FN0(GetAlignment, align_T)
BOOST_IDL_END(ILabel)

BOOST_IDL_BEGIN(IStandardButton)
  BOOST_IDL_FN0(GetLabel, ILabel)
  BOOST_IDL_FN0(GetDims, dim_struct)
BOOST_IDL_END(IStandardButton)

Using the interfaces would be done by simply declaring classes which
implement the interfaces implicitly as below:

class CenteredLabel {
  public:
    CenteredLabel(string s) : text(s) { };
    string GetText() { return text; }
    string GetAlignment() { retun enumAlignHCenterVCenter; }
  private:
    string text;
}

class StandardOkButton {
  public:
    OkButton() : label("OK") { }
    dim_struct GetDims() { return dim_struct(100,50); }
    ILabel GetLabel() { return label; }
  private:
    CenteredLabel label;
}

Is the value of such as approach apparent or are more detailed examples
warrranted?

Christopher Diggins
http://www.cdiggins.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk