Separation of class definition to several different headline files



  • I would like to know how legitimate and effective this is (generally, this is being implemented and is kind of working). C++, yes.

    For example, there's a big class that can be arranged for modules. These modules, however, are sufficiently linked to each other, constantly causing each other ' s methods, and so on. Let's say one performs, the other controls, the third serves. For the most part, it's for convenience to keep up with tons of code and not to find some kind of operation there.

    I mean, splitting into several classes is rather difficult, but it will have to fight the copies of these classes in order to achieve the unity of the data in the already high-grade classroom.static It doesn't work out if you have to start this big class in parallel, and the data should not cross, that is, be different? Besides, I don't want anyone to see any of these possible classes, other than who needs to use them, which is not beyond the boundaries of this big class, but in fact, not beyond the boundaries of the areas of visibility of any of its modules that would become classes (though later). I think we can do it, but it's mutton.

    But in different modules (let's say we've already smashed them on different scales of data, different descriptions of methods. And to keep them out of a single headline, you could be split into different headlines, connecting everyone to your module. Some fields and some prototype functions will meet in several headline files, but the functions themselves will only be performed in one place.

    I mean, like,

    // A.h
    #pragma once
    

    class MyClass
    {
    MyClass();
    void func1();
    void func2();
    }


    // A.cpp
    #include "stdafx.h"
    #include "A.h"

    MyClass::MyClass()
    { /* какой-то код */ }

    MyClass::func1()
    { func2(); } // func1 прекрасно видит func2


    // B.h
    #pragma once

    class MyClass
    {
    void func2();
    void func3();
    }


    // B.cpp
    #include "stdafx.h"
    #include "B.h"

    MyClass::func2()
    { /* какой-то код */ }

    MyClass::func3()
    { func1(); } // нет, он не будет компилироваться, func1 ему не известна



  • I'll close the question because no one will answer. There is a discussion above which suggests that:

    • It works;
    • But it could lead to confusion with the headers;
    • This means that there is a class with a large number of responsibilities that many seem redundant, and, on the team of developers, such a code would cause confusion.

    Refacturing raises two problems:

    • Work with copies: the algorithm should maintain data unity, but only in one line of general events, and these Linercs may be parallel;
    • Accessibility: Class interfaces should be invisible from outside but accessible where they really need it.

    I've solved these problems in a way that:

    • One class has remained, but the sub-grades responsible for modularity have now been identified and are integrated into each other;
    • They are dealt with by means of indexes, except in cases where static methods are applied;
    • Each modular introduced shall be declared in the privatized zone of the class, and there may also be something in the module;
    • As a result, there are problems with overhead costs for investment and the need for a code slate А::B::C::func() {...};
    • However, this solves the problem of external accessibility;
    • But there is still a problem of undesirable accessibility from within, as the classrooms are likely to be used private Accumulating class which is not specified in the standard and is not recommended;
    • All data are stored in some storage facility with get/set- Meths which are closed to the outside of an enclosed class;
    • Copies of this repository are alternately transferred from class to class: each time a parameterized designer of the built class to which a copy of the repository is displayed through the index;
    • In the destructor, everything is properly destroyed.

    In the end, the code changed in volumes:

    • Heading files were reduced due to the lack of matching fields and methods;
    • A separate data module has been installed;
    • Implementation files have increased markedly, as work is now done through or through the indexes and the transfer of the universal indicator void* for some data get- Repository marker requires follow-up. static_cast<type*>(void* ptr)

    To be honest, I was expecting an answer, as my original version would work on a statistical msvc (and other compilers) and a companion, whether everything would look really like I've planned or not in terms of assembly and other, but alas. And the reference to "spogetti" is relatively closely linked to each other, the processor and the servicer in the process, representing aspects of a single whole, I don't think they were sufficiently relevant to the subject matter.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2