반복되는 구조를 만들고 그 안에 저장된 객체가 왼쪽에서 오른쪽 순으로 그려집니다. 그러나 드로어 블 객체와 함께 저장되는 컨테이너가있을 것입니다. 이 컨테이너들은 드로어 블 객체가 서로 위에 그려지는 드로잉 스택으로 간주합니다. 필자는 약간의 거친 의사 코드를 작성했지만, 컨테이너와 드로어 블 객체를 모두 상속받을 수있는 공용 인터페이스를 만들 수는 없습니다. 내 목표는 컨테이너와 드로어 블 객체 간의 공통 인터페이스입니다. 컨테이너 안에 드로어 블 오브젝트가 하나 밖에 없더라도 컨테이너를 삽입하면됩니다. 더 많은 메모리를 차지하고 속도가 느려집니다. 나는 또한 올바른 호출을하기 위해 객체를 형 변환하는 것을 피하고 싶지 않다. 누군가 내가해야 할 일에 대해 제안 할 수 있었는지, 나는 가장 진보 된 프로그래머는 아니지만 속도와 코드 축소를 위해 노력합니다. 여기에 지금까지 무엇을 가지고 (I 난 그냥 모르는 부양 일치하지 않는 인터페이스 호출의 일부를 알고 무엇을) :객체와 컨테이너가 포함 된 컨테이너
class IDrawable {
protected:
signal_t sig; // this is an enumeration
public:
void paint(QPainter &painter); // This functionality will be defined here since it is painting to a pixmap
virtual void reset() = 0;
virtual void init() = 0; // Setup code will go here
virtual void update(float) = 0;
};
class Signal : public virtual IDrawable {
private:
bool state; // By default this will be false
public:
Signal();
virtual ~Signal();
// Parameters for update is 0 or 1, since the graphic is just toggled on or off
virtual void update(float) = 0; // Drawing happens here. Will draw to pixmap
bool state() {return state;}
};
class Gage : public virtual IDrawable {
private:
float cur_val;
public:
Gage();
virtual ~Gage();
virtual void init() = 0; // Setup code will go here
virtual void update(float) = 0; // Drawing happens here. Will draw to pixmap
};
class TextGage : public virtual Gage {
public:
TextGage();
virtual ~TextGage();
void update(float); // Define update functionality here
};
// a stack can coexist with a Gage object in a container
class DrawableStack : public virtual IDrawable {
private:
QMap<signal_t, IDrawable*> *Stack;
public:
DrawableStack();
virtual ~DrawableStack();
void init() {
Stack = new QMap<signal_t, IDrawable*>();
}
void update(signal_t,float); // Drawing happens here. Will draw to pixmap
void setStack(QMap<IDrawable*> *gageStack) {
Stack = gageStack;
}
void push(IDrawable* node) {
Stack.insert(node->sigType, node);
}
};
가 참으로이 내가 찾던 정확히 ... 당신이 찾고있는 것은 복합 패턴입니다 생각합니다. 이제 특정 신호 ID가있는 어린이를 검색하는 방법을 알아 내야 만합니다. – Talguy
방문객을위한 것으로 보입니다.) http://en.wikipedia.org/wiki/Visitor_pattern –