OOP Fundamentals and its Amiga E implemetations (Part 4)


Object Inheritance in AmigaE V3.x

One of the tricks you'll learn coding in OOP in AmigaE is that sometimes it is better not to inherit directly one object to create another one, but to incapsulate the old object inside the new one, so you can completely hide it from user (programmer) view.

This way of coding has some advantages: first of all, the new object will not have all methods of its superclass and this, even if at a first sight may sound more like limitation than a feature, assures that object's method lists will not grow badly while we inherit an object after another for too many times. As second advantage, we can refine a method with a different number of params from the original one, without generate compiler's warnings/errors. Third, without the SUPER command, our code is clearer and easyer to read.

This little coding trick, at last, produces smaller and more functional objects: methods are just those that effectively the object needs and not just a trail inherited from a previous object.


Inheritance Yes, Inheritance No

At this point, we have to really evaluate how much we'll gain inheriting an object instead of inglobing it inside a new one. Advantages, but also disadvantages deriving from the wrong choose. If, for example, we intend to write an object which is really an extension of the previous, it is better to consider the opportunity of inherit it. Our new object will inherit all methods of its superclass, starting with a huge of info. It is also possible we'll find that our new object has too many methods. Almost certainly much more than we needed, if we did not intend to just refine or enlarge our previous object.

A second choice is given by writing a new object that incapsulates the previous one. In this way, methods of the original object will not become a part of the new object we are creating, unless we did not refine them again. This way of coding is quite particular and has some disadvantages: if in the new object some methods execute exactly the same things of original methods we'll have to refine them anyway, increasing the final size of our object.

Anyway, I think that you can approach the OOP also towards this way of coding, inglobing one object inside another: sometimes there are more advantages than disadvantages.


Main Page


    Written By: Fabio Rotondo      e-mail: fsoft@intercom.it
                C.so Vercelli 9
                28100 Novara
                ITALY               tel:    (ITA) - (0)321 459676