typedef float Coord; Coord coords[] = { 1,2,3 }; int b[] = { 1,2,2 }; #if 0 class Compositor { public: void Compose(){} }; class Composition { public: void Repair(); Compositor* _compositor; }; void Composition::Repair () { _compositor->Compose(); // merge results with existing composition, if necessary } template <class AStrategy> class Context { void Operation() { theStrategy.DoAlgorithm(); } // ... private: AStrategy theStrategy; }; class MyStrategy { public: void DoAlgorithm(){} }; Context<MyStrategy> aContext; #endif class Compositor; class Component; class Composition { public: explicit Composition(Compositor* pCompositor) { _compositor = pCompositor; } void Repair(); private: Compositor* _compositor; Component* _components; // the list of components int _componentCount; // the number of components int _lineWidth; // the Composition's line width int* _lineBreaks; // the position of linebreaks // in components int _lineCount; // the number of lines }; class Compositor { public: virtual int Compose( Coord natural[], Coord stretch[], Coord shrink[], int componentCount, int lineWidth, int breaks[] ) = 0; protected: Compositor(){ } }; void Composition::Repair () { Coord* natural; Coord* stretchability; Coord* shrinkability; int componentCount; int* breaks; // prepare the arrays with the desired component sizes // ... /* */ // kills comiler warnings natural = coords; stretchability = coords; shrinkability = coords; componentCount = 1; breaks = b; /* */ // determine where the breaks are: int breakCount; breakCount = _compositor->Compose( natural, stretchability, shrinkability, componentCount, _lineWidth, breaks ); /* */ // lay out components according to breaks // ... } class SimpleCompositor : public Compositor { public: SimpleCompositor(){ } virtual int Compose( Coord natural[], Coord stretch[], Coord shrink[], int componentCount, int lineWidth, int breaks[] ) { return 0; } // ... }; class TeXCompositor : public Compositor { public: TeXCompositor() { } virtual int Compose( Coord natural[], Coord stretch[], Coord shrink[], int componentCount, int lineWidth, int breaks[] ) { return 0; } // ... }; class ArrayCompositor : public Compositor { public: explicit ArrayCompositor(int interval){ } virtual int Compose( Coord natural[], Coord stretch[], Coord shrink[], int componentCount, int lineWidth, int breaks[] ) { return 0; } // ... }; int _tmain(int argc, _TCHAR* argv[]) { Composition* quick = new Composition(new SimpleCompositor); quick->Repair(); Composition* slick = new Composition(new TeXCompositor); slick->Repair(); Composition* iconic = new Composition(new ArrayCompositor(100)); iconic->Repair(); return 0; }