Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
There are two questions.

The first is that it seemed better to just add a new constructor than add a bunch of mutator functions to a class in order to create a new instance. Would you agree? Or would it be better to add mutators, or are constructors problematic?

Also, it it OK style to use the m_Variable instead of accessor functions if they're inside functions of the class that house the m_variable?
Posted

Go for constructors every time unless there's a good reason not to. Most classes don't actually need functions to change or read one squitty bit of state. Generally if you think about an objects behaviour rather than how it does it you won't find a lot of reasons to have "setters/mutators."

Inside member functions there's no point in using any access functions. If you've got them and they do something useful apart from just read back a bit of data then you might as well use them but I wouldn't bother writing new ones just for internal use.

Cheers,

Ash
 
Share this answer
 
It's up to you really - there are no hard rules on this. Having multiple constructor overloads is fairly typical and is not normally considered problematic. Of course you can take it too far and make it a maintenance nightmare.

And yes, it's fine to use the private field from within the class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900