コンポジット デザイン パターンを使用してデコレータを適用しようとしています。私が見つけたリソースのほとんどは、これら 2 つのパターンがこのように連携することが多いと述べていますが、これがどのように機能するかの例を示すものはありません。おそらくストレッチですが、この場合の実装を推定する例を教えてください。
私のクラスの概要は以下のとおりです。
ThorSoldier は AvengerSoldier を継承し、AvengerSoldier は Unit を継承しています。各「アベンジャー」は同様の構造に従います。
class Unit // Component (Not abstract, contains all the implementations that units have)
{
public:
virtual void levelUp(){}
// Other implementations
};
class NickFurySoldier // Manager (Composite)
{
public:
virtual void levelUp();// Should apply the decorators to primatives
void add(Unit* avenger);
private:
std::vector<Unit*> avengers;
};
class ThorSoldier: public AvengerSoldier
{
// Example of a primative that has to be decorated
};
class ThorDecorator: public ThorSoldier
{
public:
ThorDecorator(ThorSoldier* soldier);
// Other Implementations
};
class LightningThor: public ThorDecorator // Example of the decoration that should be implemented
{
public:
LightningThor(ThorSoldier* soldier);
// Other implementations
};