I would like to know how legitimate and effective this is (in general, it is implemented and seems to work). C ++ language, yes.
For example, there is a large class that can be divided into modules. These modules, however, are rather strongly connected with each other, constantly invoke methods of each other, and so on. Let's say one performs, the other controls, the third serves. For the most part, this is for convenience, so as not to scroll through tons of code and not to look for some kind of functionality.
That is, the division into several classes is rather difficult, and you have to struggle with instances of these classes to achieve data unity in an already conventional large class ( static doesn’t fit at all: suddenly you have to run this large class in parallel, and then the data should not overlap, t Should there be different instances?). Besides, I don’t want anyone to see this or that functionality of these possible classes, besides who really needs to use their capabilities, and this is the maximum - not further than the boundaries of this large class, but in fact - not further than the boundaries of areas the visibility of one or another of its modules that would become classes (a little later about it). I think you can do it, but a chore.
But in different modules (for example, we have already broken them into different .cpp-files) different data fields, different method descriptions will be needed. And in order not to throw out a whole stop on them from the same header file, it would be possible to divide it into different header files, each connecting to its own module. Some fields and some function prototypes will appear in several header files, but the functions themselves will be implemented only somewhere in one place.
Something like this means:
// Ah #pragma once class MyClass { MyClass(); void func1(); void func2(); } * * * // A.cpp #include "stdafx.h" #include "Ah" MyClass::MyClass() { /* какой-то код */ } MyClass::func1() { func2(); } // func1 прекрасно видит func2 * * * // Bh #pragma once class MyClass { void func2(); void func3(); } * * * // B.cpp #include "stdafx.h" #include "Bh" MyClass::func2() { /* какой-то код */ } MyClass::func3() { func1(); } // нет, он не будет компилироваться, func1 ему не известна