Distribution of many small classes

I have a base class EventArgs. This leads to many, many specializations that represent event arguments for a particular type of event. Users of these events may need several or more of these argument classes.

My question is whether you would provide a header file for each type (e.g. 50+ header files for different ones), would you try to group them in families and have a common header file for them, or would you throw caution into the window and nest them into one simple header file that you can simply include?

Another approach might be to have 50 header files, and then I could introduce some “family” header files that included specific ones. Not sure about naming conventions for such things, so obviously there is where.

I know that there cannot be a hard and fast rule, but it is interesting what other developers did when they wrote a lot of small classes.

Thanks in advance.

+3
source share
5 answers

I would have to put two classes in separate headers in one of the following cases:

  • they are huge
  • they are not connected or are unlikely to be used together
  • each one introduces its own title dependencies

. , " ", .

"", , ( ) , - IDE, , . , , .

+3

, , , . 50+ .

+1

?

0

, . ( ) . . , . , .

, , Poco ++. , . , (. Exception.h Exception.cpp).

0

if they belong to the same inheritance hierarchy, put them in the same .h file. This will help you choose the right order for your classes. One of the lesser-known compile-time checks in C ++ is based on the correct order of classes in the .h file.

0
source

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


All Articles