코어 로직을 사용하는 Engine
클래스가 있지만이 클래스는 비슷한 기능을 가진 타사 엔진으로 대체 될 가능성이 있으므로 나머지 클래스에 최소한의 영향을주고 싶습니다. 신청.C++ 핵심 클래스 가시성 제한 및 깨끗한 인터페이스 제공
나는 Engine
클래스와의 간단한 인터페이스를 허용하는 Adapter
이라는 또 다른 클래스가 있으며 Engine
클래스 위에 몇 가지 부가 기능을 제공합니다.
그런 다음 훨씬 간단한 인터페이스를 가진 나머지 응용 프로그램에 노출하고자하는 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