Mutual friendship and pointers: What Pattern or anti-pattern is this?

In studying the C++ source of a massive app, I find this pattern (the syntax for the example may be sketchy, but the essential details are there):

class A  :  X
   friend B;
   B *parent;

class B  : Y
   friend A;
   A *myhelper;

Perhaps it is meaningful that class B is really named AHelper, but I'm more curious about this fairly symmetrical relation between two classes. Is this part of one of the standard GoF patterns, or an established anti-pattern? Is there some concept or way of understanding this besides the details, a whole greater than the parts?

Would it make sense to combine A and B into one class? There is the matter of each class being inherited from other classes X, Y. I am eager to refactor this code to make it more maintainable and smaller.


Depends on what the classes are doing. If it's something like the iterator pattern (i.e. std::vector<t> and std::vector<t>::iterator), then it can be used for something good.

On the other hand, if the classes are doing fundamentally different things, it's probably best if they are only exposed to each other using their public interfaces.

In other words, I don't think it's a pattern or anti-pattern -- it depends entirely upon the use of the actual classes in question.

Need Your Help

Ajax Flexcroll with JQuery Mobile not loaded

jquery ajax jquery-mobile mobile

I'm using Flexcroll and I got problem with Ajax.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.