-3

I have class with virtual init() function which is defined in derived class, and other function initializing this class and calling init function. How to name this other function?

I tried something like doInit but it looks like private function. init function name cannot be changed.

public:
bool myclass::this_other_function_init( params )
{
    systemInit(this);
    init();
    ...
    return true;
}
virtual init() = 0;

Private method naming convention - this topic shows great how to name private method, but now I have to do opposite name public method.

EDIT: how do you name your Initialization functions? init, initialize, start....etc ???

Community
  • 1
  • 1
Yevhen
  • 1,897
  • 2
  • 14
  • 25
  • 1
    I don't understand how any of these functions you describe relate to each other. Please explain in more detail possibly with code samples. – djechlin Aug 03 '12 at 21:03
  • 4
    So you call a function to call your initializing function... Sounds fishy. Why would you need more than one? – chris Aug 03 '12 at 21:06

4 Answers4

0

Make your public function the most readable and easy to understand. Hopefully in your case you don't even need it at all, since your constructor should be doing the "init" work.

Then name your (hopefully) protected virtual function what it is meant to do, perhaps more specific than just Init() if you can.

The fact that you are thinking of 2 functions that can have interchangable names but meant for different purposes is a hint that you may want to re-think the class structure.

LMC
  • 302
  • 3
  • 13
  • I am not using constructor for initialization because I have dependencies between class, that can be made after objects construction. – Yevhen Aug 03 '12 at 21:24
  • If the dependencies are truly unavoidable, then at least name your public "Init" function what it is meant to do. Say, GetResource(), Open(), etc. to give your caller more information. – LMC Aug 03 '12 at 21:32
0

Any non-conflicting function name of your preference would do just fine. It's not something you should worry about so much.

Desmond Hume
  • 8,037
  • 14
  • 65
  • 112
0

Naming is important. Right names are important but also coherence is important. Create your naming convention style and use it. I suggest you to read Clean Code. It explains well how to name your class and many other stuff to create code that explains itself.

Regarding your specific problem, two initialization are hard to understand As a user of our class, I don't understand why I must call two different initialization, because one must be sufficient, at usually is. I suggest you to implement all initialization code only in the derived virtual member. I suggest you some refactoring, or explain better what these functions do.

Jepessen
  • 11,744
  • 14
  • 82
  • 149
  • You do not have to call these two function just that 'other' function. 'init' is an interface method. – Yevhen Aug 04 '12 at 05:18
0

Use a name that will explain what function does rather than what is so when you look at this a 1 year later and you will understand.