Extend
Not logged in

Extending Framework

The framework is designed to make it easy as possible to add specialized flowers with their own appearance and behaviour.

Suppose you want to add a specialized flower with the following features:

The following steps are required:

  1. Define interface to new specialized flower
    	class cVessel : public cFlower {
    	public:
    		cVessel();
    		void Paint( wxPaintDC& dc );
    
    
    };
  2. Re-implement constructor
    cVessel::cVessel()
    {
    	myType = "Vessel";
    	setName();
    	AddParam( "Volume (liters) " );
    }
    
  3. Re-implement painter

    void cVessel::Paint( wxPaintDC& dc )
    {
    	dc.DrawRectangle( myX, myY, 2*mySize, mySize );
    }
    
  4. Add new type to flower factory

    	class cFlowerFactory 
    	{
    	public:
    		enum type {
    			base,
    			pump,
    			vessel
    			last_type_plus_1
    		};
    
    
    cFlowerFactory::cFlowerFactory( int IDM_CreateGeneric ) { myMenu.Append( IDM_CreateGeneric,"Generic"); myMenu.Append( IDM_CreateGeneric+pump,"Pump"); myMenu.Append( IDM_CreateGeneric+vessel,"Vessel");
    }

    cFlower* cFlowerFactory::Construct( type t ) { switch( t ) { default: case base: return new cFlower( ); break; case pump: return new cPump( ); break; case vessel: return new cVessel( ); break; } }

  5. Add new type to vase reader

    bool cVase::Read( const std::string& filename )
    ...
        else if( type == L"Vessel" )
           Add( cFlower::vessel );
    ...
    

Compile and run!