コアロジックを持つEngine
クラスがありますが、このクラスは同様の機能を持つサードパーティエンジンに置き換えられる可能性があります。応用。C++コアクラスの可視性を制限してクリーンなインターフェイスを提供する
IはEngine
クラスに単純なインタフェースを可能にし、またEngine
クラスの上にいくつかの付加価値機能を提供Adapter
と呼ばれる別のクラスを持っています。
私はOrderProcessor
という別のクラスを持っています。これは、はるかに単純なインターフェイスを持つアプリケーションの残りの部分に公開したいと思っています。
Engine
とAdapter
は残りのアプリケーションから隠され、OrderProcesseor
は残りのアプリケーションのための唯一のインターフェイスです。
これを設計するにはどうすればよいですか、どのアクセス修飾子をどこで使用するのですか?それを行うデザインパターンはありますか?
これは私が持っているものですが、私はそれが正しいとは思わないです。あなたはよりきめ細かいアクセス制限をしたい場合は 'キータグ' を作る、
class OrderProcessor
{
public:
OrderProcessor();
~OrderProcessor();
Stats SendStats();
ManageInventory();
private:
class Engine
{
// ...
};
class Adapter : public Engine
{
// ...
};
Adapter adapter;
};
:
//This is the core functionality. Might have to replace this class with a third //party implementation
//Want to hide it as much as possible
class Engine
{
private:
char* ip;
char* port;
protected:
Engine();
bool Connect();
bool DisConnect();
bool SendOrder(Message msg);
bool CancelOrder (CancelMessage cxl);
Message ReceiveOrder();
};
//This is an interface to the engine and provides value added functions
//Don't want this known to anyone except the OrderPRocessor
class Adapter : public Engine
{
private:
int TotalAmount;
double DollarAmount;
protected:
bool Start(char*ip, char* port); //this will call Engine's connect() and do other things
bool Stop(); //this will call Engine's Disconnect
int TotalInventory();
double TotalSales();
double TotalCommission();
};
//This class is the main interface to the rest of the application for order
//processing related functionality.
class OrderProcessor
{
public:
OrderProcessor();
~OrderProcessor();
Stats SendStats();
ManageInventory();
private:
Adapter adapter;
};
実際にはpImplイディオムが実際に使用されていますか?(http://stackoverflow.com/questions/8972588/is-the-pimpl-idiom-really-used-in-practice) – lcs
'ip'少なくとも 'const char *'でなければなりません。ポート、おそらく、int。 – Igor