Sign in to follow this  
wolfram

general oo-design issues

Recommended Posts

wolfram    122
Hello, from an efficient programming perspective, are there any problems that should be avoided when making object-oriented design? In other words: What problems come along with object-oriented implementations? (just wondering, for no particulat reason!)

Share this post


Link to post
Share on other sites
bballmitch    100
Almost none. I think that if you make any game thats even SLIGHTLY complicated, using OOP is going to make it much more efficient. Not to mention it makes the code easier to read.

Share this post


Link to post
Share on other sites
janoside    214
Of course, as with any high-level technique, there is overhead. Unfortunately, the overhead can often be worsened the cleaner your design is. Fortunately, the overhead is never that high.

In non-object-oriented programming, a call to a function does simply that, calls the function. In good OO design, there is often a hierarchical organization of classes and different instances of those classes often provide different implementations for the same function (method). One of the strengths of OO use is its ability to treat different implementations of the same method (of different classes in the same hierarchy) as the same method. A necessary consequence of this is that the OO runtime must decide dynamically what actual method to call when a polymorphic instance is called. In order to maximize performance in an OO design, you should minimize the number of methods in a class that are marked as virtual (C++/C# syntax) and are overridden. However, this practice can have an adverse effect on your OO design, so the key is to find a balance.

This is only one performance concern of OO design, any book on the subject will enumerate them all. However, as I said, the performance hit of this is never large, and as bballmitch said, the practice does in general improve overall performance. I personally value cleanness and coherency of design far above performance.

janoside

Share this post


Link to post
Share on other sites
wolfram    122
Thanks for a good explanation! Are the other aspects that might overhead a program when using OO design? (I'm afraid i dont own any books about this subject!)

Share this post


Link to post
Share on other sites
discman1028    212
Hmmm, use C++ macros, templates, and inheritance (not polymorphism unless really needed). These three are compile-time time-savers for the programmer (i.e. no runtime performance hit).

Correct me if I'm wrong!

Of course, don't find reasons to use these complicated things... use them when it helps!

Share this post


Link to post
Share on other sites
flangazor    516
Quote:
Original post by discman1028
Hmmm, use C++ macros, templates, and inheritance (not polymorphism unless really needed). These three are compile-time time-savers for the programmer (i.e. no runtime performance hit).

Correct me if I'm wrong!

Of course, don't find reasons to use these complicated things... use them when it helps!


Inheritance Dynamic Polymorphism requires a vtable lookup so there is a small hit.

The OP's question is too open ended. Sure, you can make slow programs with OOP, but you can always make crappy programs no matter what systems you use.

Quote:
from an efficient programming perspective, are there any problems that should be avoided when making object-oriented design? In other words: What problems come along with object-oriented implementations?
Avoid worrying about it until you have a program that does what you want. A program that does what you want is more useful than a program that doesn't do what you want but is quick. If you need it to be quick, profile.

You really cannot guess where bottlenecks will be. Knuth said this in the 70s out of his experience writing TeX. I'm saying it now in my experience writing code generators and realtime databases.

Quote:
I personally value cleanness and coherency of design far above performance.
Quoted for truth.

[Edited by - flangazor on March 16, 2006 10:27:50 PM]

Share this post


Link to post
Share on other sites
janoside    214
Quote:
Hmmm, use C++ macros, templates, and inheritance (not polymorphism unless really needed)


Polymorphism is a cornerstone of OO programming, avoiding its use is ridiculous in OO design.

Share this post


Link to post
Share on other sites
Trap    684
I don't think there is anything special you need to be aware of. Just the usual "use algorithms with good time-complexity" and "use data structures with good space-complexity".

The only additional things you need to know are the time- and space-complexities of the OOP-features which mostly are O(1) and thus nothing to worry about.

Share this post


Link to post
Share on other sites
Enigma    1410
Quote:
Original post by flangazor
Inheritance requires a vtable lookup so there is a small hit.

Dynamic polymorphism (aka virtual functions) (usually) requires a vtable lookup (assuming a vtable implementation). Plain inheritance doesn't. See for example the vector implementation that ships with your compiler. It likely uses inheritance without dynamic polymorphism and without any performance penalty (in fact it likely uses it to gain a performance enhancement via the empty base optimisation).

Σnigma

Share this post


Link to post
Share on other sites
flangazor    516
Quote:
Original post by Enigma
Quote:
Original post by flangazor
Inheritance requires a vtable lookup so there is a small hit.

Dynamic polymorphism (aka virtual functions) (usually) requires a vtable lookup (assuming a vtable implementation). Plain inheritance doesn't. See for example the vector implementation that ships with your compiler. It likely uses inheritance without dynamic polymorphism and without any performance penalty (in fact it likely uses it to gain a performance enhancement via the empty base optimisation).

Σnigma

Well spotted, Snigma. I meant to say what janoside said. In fact, I'll just drop out of this thread and let janoside speak for me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this