From: Panayotis K. <pan...@pa...> - 2010-09-11 12:17:24
|
For quite some time there is no decision whether it is preferable to use abstract classes or interfaces. With this email I'd propose to use only abstract classes instead of interfaces and I hope I will convince you :) First of all I know the disadvantages. By using interfaces we can not reuse the same objects and thus we usually create inner classes (so we create one class more). A second problem has to do with concept: in ObjC there is a use of protocols and not interfaces. The problem is, although it looks like we make economy by reusing the same object, in reality under the current xmlvm implementation, this is not the case. In order to properly support java interfaces, a "secret" glue object is used in every case (in which object we have absolutely no control upon). When using abstract classes there is 1-1 correspondence. Even if we use inner classes (which is a common and well known technique), we have absolute control on this object. In any case, worst case scenario, we have to define/use one (an only one) object of this abstract class. Back to the interface implementation, the minimum number of objects is one: the glue object. Though, in the case of an inner object (or any time we don't reuse a given object) , the number of objects rises to two! In all cases, interface implementation is more demanding than abstract classes, and more complex. For this reason I propose to use everywhere in XMLVM compatibility library abstract classes instead of interfaces - even for trivial cases. -- Panayotis |