Interface structure and implementation?

I am new to developing large C ++ programs. I am writing a series of operations, each of which has its own class, which will be called by the ProcessMgr class.

I use ProcessMgr as an interface class from which each operation can be called:

 class ProcessMgr { private: class OperationOne; class OperationTwo; class OperationThree; } class ProcessMgr::OperationOne { public: ... }; class ProcessMgr::OperationTwo { public: ... }; class ProcessMgr::OperationThree { public: ... }; 

This allows me to control the types of access to the Operation classes, so without exposing most of their base code.

It is important that the user of this code can only interact with the Operation classes in a certain way and not have full access to the entire contents of the Operations classes.

My questions:

1) Is this a good approach to developing large programs? Most libraries like CURL are structured this way?

2) Are there better / more efficient methods for separating the interface and implementation?

+5
source share
1 answer

A regular C ++ interface (or other OOP languages) contains definitions. "Operational classes" must be inferred from the interface so that you separate the implementation from the client. This principle is called the Dependency Inversion Principle (DIP) .

The general UML diagram from DIP is as follows: enter image description here

Since the Client is only familiar with the interface, you can control access to certain subclasses. An implementation might 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() { ... } } 

DIP is a principle in a series of very good principles called SOLID . To design large projects, you need to do a lot and learn. But SOLID principles are a good start to understanding how to develop software applications.

+4
source

Source: https://habr.com/ru/post/1263499/


All Articles