Implementation in global functions or in a class wrapped in global functions

I need to implement a set of 60 functions according to predefined signatures. They should be global functions, not some functions of class members. When I implement them, I use a set of well-executed classes provided by a third-party partner.

My implementation of most functions is rather short, about 5-10 lines and mainly concerns various accesses to these third-party classes. For some more complex functions, I created a couple of new classes that deal with all complex things, and I use them also in functions. All status information is stored in the static members of my and third-party classes, so I don’t need to create global variables.

Question: It would be better if I implemented one large class with 60 member functions and did it implement the whole implementation (that is, now in global functions)? And each of the functions that I need to write will simply call the corresponding member function in the class.

+3
source share
4 answers

All status information is stored in the static members of my and third-party classes, so I don’t need to create global variables.

This is the key point. No, they certainly should not be introduced into classes. Classes are designed to create objects. In your situation, you would use them as an area for data and functions. But this is what namespaces already solve better:

namespace stuff {
    ... 60 functions ...
    namespace baz {
        ... if you want, you can have nested namespaces, to ...
        ... categorize the functions ...
    }

    namespace data {
        ... you can put data into an extra namespace if you want ...
    }
}

, , - .

+4

?

, .

, , , .

+2

litb, , . , class , - . , , - - .

using namespace stuff;! , :

#include <stuff.h>
void some_function() {
    stuff::function_wrapper();
}

:

#include <stuff.h>
using namespace stuff;
void some_function() {
    function_wrapper();
}

, - namespace , static, .

+1

, " " . 60 , , , . OO API, .

0

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


All Articles