class Trait
Defined at line 34 of file ../../src/ui/lib/escher/base/trait.h
This class serves to document a C++ design pattern which extends the idea of
a pure interface by adding non-virtual methods which are defined in terms of
pure virtual methods that subclasses are required to implement.
For example, a RectangleTrait adds the ability to compute an area to any
class that can provide a width and a height:
class RectangleTrait {
public:
float area() const { return width() * height(); }
private:
virtual float width() const = 0;
virtual float height() const = 0;
};
The key feature of this design pattern is its statelessness (i.e. the trait
class has no instance variables), and is therefore safe to use with multiple
inheritance, for the same reasons it is safe for a class to implement several
pure virtual interfaces.
NOTE: Being unaware of an idiomatic name for this C++ pattern, we take the
name from an analogous language feature first introduced in Squeak, and soon
popularized in Scala: http://scg.unibe.ch/research/traits.
Protected Methods
void ~Trait ()
Defined at line 36 of file ../../src/ui/lib/escher/base/trait.h