例程實作
----庖丁解羊(下)
#include <iostream>
#include <string>
using namespace std;
class Part{
public:
virtual void Draw()=0;
virtual ~Part(){}
};
class Shape{
public:
Shape( string const& _s ):data( _s ){}
void Draw( unsigned color )
{
cout << data << " with color :" << hex << color << endl;
} //提供了借口,但是沒有實現繪圖
private:
string data;
//讀者可以自己實現繪圖部分
};
//絨毛,骨架,胸,腹,背,眼睛,鼻子,嘴巴,心,脾,肝,腸,腎,腳,尾巴,耳朵,肺,胃{{部分,顯示=輪廓+顏色},輪廓[1],顏色[1]}
class BasePart : public Part{
public:
BasePart( string const& _s , unsigned _c ):shape( _s ),color( _c ){}
void Draw()
{
shape.Draw( color );
}
private:
Shape shape;