|
-
March 4th, 2013, 08:44 AM
#5
Re: General Object-Orientated Question
The first approach is the fastest, but is less elegant. The third approach makes the code the most readable, but if there are lots of embedded classes within each other, this seems quite an inefficient method.
Don't assume until you tried it.
For inline functions, the compiler will optimize this so that the binary does the same as directly changing the variable.
Meanwhile you get the benefit of a better design.
That said. All 3 approaches are valid. And there may be considerations other than "best design from a pure c++ perspective" that prefer one approach over the other. If you have some kind of databinding mechanism in your program then direct access to the variables (or pointer/reference to them) may be required in that case accessor functions tend to be cumbersome. You could expose the databinding through an additional member, but again, that may have it's own issues.
Long story short: unless you have a good reason not to. you typically want to go with the best design paradigms, because that gives you the most benefits long term.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|