lundi 25 avril 2022

Refactoring : delegate friendship in sub-functions

I refactor a code where a class has a friend function doing a lot of stuff.

class Foo
{
  friend void do_something(Foo& foo);
};

void do_something(Foo& foo)
{
  // More than 2000 lines of ugly code
}

I would like to split the content of do_something in several small functions. Something looking like this :

void do_something(Foo& foo)
{
  if(case_1) do_1(foo);
  else if(case_2) do_2(foo);
  else if(case_3) do_3(foo);
  //...
}

Is there a design where I can transfert the friendship to the sub-fuctions do_x(Foo&) without having to declare them in the class, or something similar in order to split the code ?

Note : C++11 only

Note : I don't want to write the sub-functions as maccros

Aucun commentaire:

Enregistrer un commentaire