Mutual friendship and pointers: which pattern or anti-pattern?

When I study the source of a massive C ++ application, I find this template (the syntax for the example may be sketchy, but there are significant details):

class A  :  X
   friend B;
   B *parent;
   ...stuff...

class B  : Y
   friend A;
   A *myhelper;
   ...stuff...

It may make sense that class B is actually called AHelper, but I'm more curious about this rather symmetrical relationship between the two classes. Is this part of one of the standard GoF templates or an installed anti-template? Is there any concept or way of understanding this, other than the details, the whole, greater than the parts?

Would it be appropriate to combine A and B in one class? There is a question that each class is inherited from other classes X, Y. I really want to reorganize this code to make it more convenient and convenient.

+3
2

, . (.. std::vector<t> std::vector<t>::iterator), - .

, , , , , .

, , - - .

+4

A B , . , , :

  • A B , .
  • A B .

, , .

, A X B, Y, , , , .

, , , .

, . .

0

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


All Articles