Existence Based Polymorphism

Richard Fabian <[email protected]>
Newsgroups gmane.games.devel.sweng
Message-ID <[email protected]>
On 28 May 2010 17:01, JS Zirani <[email protected]> wrote:

> It is a bit out of topic, but I think you should say "OOP has
> pitfalls" instead of "OOP is bad". "OOP is bad" is really the wrong
> message.
>
>
>
I've been thinking about this a lot over the last few months, and come to
think that if OOP was not "bad", then there wouldn't be so many "effective
C++" or "C++ gotchas" like books out there. How many "pitfalls of procedural
development" books have you seen?

Although OOP does have abstraction nailed, which might be why we're seeing a
lot more coders getting stuff done in business software, some things that
OOP proclaims to do well, specifically encapsulation and polymorphism, can
be done simpler and better in games development languages we don't associate
with OOP.

Encapsulation is better handled by C. This can be seen in how you cannot
actually hide all the implementation details in C++ without using techniques
such as pImpl or virtual base classes. Each of which actually impacts
performance in some way.

On the polymorphism side, I stumbled across a slight issue in C++ that goes
away completely if you use sparse components to provide existence based
processing to provide state information.
Polymorphism comes in many flavours. If you think of C++ style
runtime-polymorphism as being the ability for the program to be unaware at
link time to know how the object will react, try to think of
dynamic-runtime-polymorphism as being the ability for the program to be
unaware _between calls_ to know how the object will react.
If you think this is pointless and crazy, may I remind you that you've
probably used Finite State Machines before.
I've already touched on this with replacing bools and enums with table
entries, but the lovely thing about this is that you get stronger
polymorphism than C++ virtuals, without the virtual call cost.

-- 
fabs();
Just because the world is full of people that think just like you, doesn't
mean the other ones can't be right.

_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.