Opinions on object oriented programming

BlitzMax Forums/BlitzMax Programming/Opinions on object oriented programming

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

How could you manage, for example, the same function as Object/Handle in BlitzMax.
It depends on what you're using Object/Handle for. In 99% of all cases you would acheive this more elegantly using polymorphism, and function/method overloading.

For instance a typical example would have you defining what Java refers to as an Interface, but which isn't actually formalized in BlitzMAX. However you can fake it well enough making a class that's entirely Abstract (having no functionality at all).

What's the point of making a Type with no functionality? It's hard to imagine, think of it as a skeleton of the functionality you can have. The point is that you now have a type that your other types can extend from. No matter what functionality they have, you can access this functionality in a uniform manner.

So if you have for example 4 types, car, bus, train and airplane -- all which have different states and behaviours, that are implemented differently you can pass them all to the same function, by using the Interface as a reference to which functionality they have. No need for Object/Handle! Additionally you don't need a field that identifies which type of object it is, as the compiler knows this, and will automatically execute the correct code for a given object, without the need to construct complex nested if ... else or Select ... case structures.

Additionally you can later add a fifth type, motorcycle, and all you have to do, is write the new implementation, and all of your old code will still work perfectly! There's no need to work out special cases for different objects, because the compiler can tell the difference, so you don't have to!