new@udel.EDU (Darren New) (04/12/90)
One feature of Smalltalk that I really like and use is the ability to put methods from one class into several files. This allows, for example, for the extention of already-defined classes with new methods. Example: I wish to extend Point and Rectangle to include a "scaleTo:" method. In Smalltalk, that method can be included into my application without disturbing the sources for the system and without recompilation of anything in the system. Even addition of new instance variables is possible (in ParcPlace systems, at least). I find this a MAJOR factor in software reusability. In C++, I (think) I have to change the header file, thereby requiring me to recompile all sources that reference that object. In Objective-C, I don't know if this is possible, especially without the sources to the other methods. In Eiffel (sp?) I understand that each class is defined within a single file, forcing me to -change- at least one system file (thereby maybe corrupting other hopefully-non-conflicting applications). I think adding overloaded functions for Ada types requires changes to the definition file, does it not? Or is that only for opaque types? In 2OL (my own experimental language) overloaded functions and messages automatically include themselves into the correct tables when compiled, thereby requiring no changes to somebody else's sources. Is my analysis of C++, Objective-C, and Eiffel correct? Does anybody know of other languages which allow the user to extend functionality of system classes/libraries/etc without changing files where the old stuff is defined? How about Ada
Rick_R_Kitts@cup.portal.com (04/12/90)
Adding a member function to a C++ class does not require recompilation of other source files which access the class unless the size of the class has changed (i.e. you added members). Also, unless you need to access the private parts of a class there is no real reason to actually modify the class definition itself. (Perhaps) the easiest thing to do is to make a derived (sub) class of the base (super) class which contains the method you want to add. Note that following this scheme could get quite messy since you could end up with a bunch of class hierarchy trees. Rick rkitts@slc.slac.stanford.edu
andyn@stpstn.UUCP (Andy Novobilski) (04/12/90)
In article <16560@estelle.udel.EDU> new@ee.udel.edu (Darren New) writes: >One feature of Smalltalk that I really like and use is the ability to >put methods from one class into several files. This allows, for example, >for the extention of already-defined classes with new methods. > >... In Objective-C, I don't know if this is possible, especially without > the sources to the other methods. > ... >Is my analysis of C++, Objective-C, and Eiffel correct? ... Darren, The Objective-C language supports the extension of pre-existing classes and class libraries by allowing one class to "pose" as another. This mechanism is invoked at runtime by the Objective-C object model and allows a programmer to insert behavior (no data) into the class hierarchy structure. The programmer uses the poseAs capabilities by defining a new class (methods only, no instance variables allowed) that sends a "poseAs:" message at initialization time indicating the class it wishes to pose as. This causes the message lookup function to check if the method is located in the posing class before checking in the original class that was posed as. The pose as functionality is made possible by Objective-C's use of dynamic binding to resolve what method should supply the requested behavior at message time. The use of dynamic binding also allows a programmer to change the methods of a class definition without having to recompile classes that subclass from it. However, if a change is made to an instance variable, then all subclasses of that class must be recompiled. If you have any additional questions, please feel free to contact us (or myself) at Stepstone. Andy N. -- Andy Novobilski | The Stepstone Corp. | The expressed views have been andyn@stepstone.com | 75 Glen Rd. | approved by a committee of three: (203)426-1875 | Sandy Hook, CT 06482 | the goldfish, blackfish, and me.
lgm@cbnewsc.ATT.COM (lawrence.g.mayka) (04/14/90)
In article <28835@cup.portal.com> Rick_R_Kitts@cup.portal.com writes: > Adding a member function to a C++ class does not require recompilation >of other source files which access the class unless the size of the >class has changed (i.e. you added members). Also, unless you need to This understates the situation a bit. The following situations may require recompilation of other source files. - Adding a virtual function may not update the virtual function table (without additional recompilation). - Adding the first virtual function to a class may insert a new (hidden) member, the virtual function table pointer, thus changing the size of the class structure. - Adding a virtual function that precedes all others textually may cause the virtual function table pointer to occur at a different location within the class structure, effectively shuffling members. - Adding a virtual function anywhere other than at the end may shuffle the virtual function table entries and thus change the offset needed to call each virtual function. - Adding a member function may shadow an external function or type of the same name. - Adding a member function with an overloaded name may shadow (via the overloading rules) another member function overloaded on that same name. Those are the only cases I can think of *offhand*. In general, the C++ language assumes global consistency (i.e., global recompilation on any change to anything). Anything less may give implementation-dependent results. Lawrence G. Mayka AT&T Bell Laboratories lgm@ihlpf.att.com Standard disclaimer.