I'm quite new to designing large programs in C++. I'm writing series of operations, each of which have their own class, which will be invoked by the ProcessMgr
class.
I'm using ProcessMgr
as an interface class, from which each operation can be invoked:
class ProcessMgr
{
private:
class OperationOne;
class OperationTwo;
class OperationThree;
}
class ProcessMgr::OperationOne
{
public:
...
};
class ProcessMgr::OperationTwo
{
public:
...
};
class ProcessMgr::OperationThree
{
public:
...
};
This enables me to control the types of access to the Operation
classes, therefore not exposing much of their underlying code.
It's important that the user of this code can only interact with the Operation
classes in specific ways and not have complete access to all the contents of the Operations
classes.
My questions:
1) Is this a good approach to designing large programs? Are most libraries, such as CURL, structured in this way?
2) Are there better/more efficient methods of separating interface and implementation?
A normal Interface in C++ (or other OOP languages) provides the definitions. The "operation-classes" must be derived from the interface, so that you decouple the implementation from the client. This principle is called the Dependency inversion principle(DIP).
A common UML-diagram from the DIP looks like the following:
Since the Client is just familiar with the Interface, you can control the access to the specific subclasses. An Implementation could look like this:
class ProcessMgr {
virtual void foo() = 0;
virutal void bar() = 0;
}
class Operation1 : public ProcessMgr {
virtual void foo() { ... }
virtual void bar() { ... }
}
class Operation2 : public ProcessMgr {
virtual void foo() { ... }
virtual void bar() { ... }
}
The DIP is a principle from a series of very good principles, called SOLID. To design big projects, there is much more to do and learn. But the SOLID-principles are a good start to understand how to design software applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With