回答:「実際のコード実装に変換するにはどうすればよいですか?」
メモとCamelCaseを含むこのUMLはJavaのように見えます
が、図のC++パターンを次に示します。
- 矢印は通常、ポインタまたはshared_ptr-sを意味します。
- 白頭の矢印は公的継承を意味し、
<<interface>>
C ++の抽象クラス、Javaのインターフェース、
- 破線の矢印が付いた白いものはメモです。この場合、実装の詳細が提供されますが、文字通り入力することもできます。
コードを見る前に、私はキャメルケースが嫌いだと言わせてください。STLやBoostなどのC ++ライブラリがそうするので、underscore_notationを実行することをお勧めします。したがって、すべてのクラスをアンダースコア表記に変更しました。
したがって、実装の一部は次のようになります。
class Abstract_platform {
public:
virtual ~Abstract_platform()=0; // this UML does not specify any functions but we make this class abstract.
};
class Platform_one : public Abstract_platform {
};
class Platform_two : public Abstract_platform {
public:
/// you should implement this make function with shared_ptr, OR NO POINTERS AT ALL but I go according to the notes
Product_one_platform_two* make_product_one();
Product_two_platform_two* make_product_two();
// I provide you with a better_make. It is better than the former make functions
// due to RVO (Return value optimization see wikipedia)
// so this is again a hint that this UML was originally for Java.
Product_one_platform_two better_make_product_one();
};
class Class1 {
private:
Abstract_platform* platform; // OR shared_ptr<Abstract_platform>, OR Abstract_platform&
Abstract_product_two* product_two;
};
/// **Implementation file**
Product_one_platform_two* Platform_two::make_product_one()
{
return new Product_one_platform_two();
}
Product_two_platform_two* Platform_two::make_product_two()
{
return new Product_two_platform_two();
}
Product_one_platform_two Platform_two::better_make_product_one()
{
return Product_one_platform_two();
}
また、人々の代わりに、「I」が「Interface」を表すハンガリアン記法をAbstract_platform
好むことにも注意してください。IPlatform