Object Programing and Objective C
keith gorlen
keith at cecil.UUCP
Mon Oct 14 02:25:13 AEST 1985
>Does Objective C provide what Smalltalk calls "blocks"? If so,
No.
>(2) My second reservation is actually a criticism of inheritance
>in general. While it is very true that data-abstraction helps
>improve the modularity of a program, inheritance requires that
>a person trying to implement a particular (sub)class need understand
>many, if not all, of the details in its chain of superclasses.
>That INCLUDES details about the "rep" (representation) of each
>superclass, since the rep, or "instance variables", are also
>inherited. "Simple" data abstraction allows rep-details to be
>hidden and ignored. Inheritance detracts from this!
This is not necessarily so. In some object-oriented languages (e.g.
C++) the private instance variables inherited by a subclass are not
(normally) accessable from the subclass, except via the superclass's
public methods. Thus, the details of the implementation of a superclass
chain are just as hidden to the subclass as they are to any user of
the superclass.
>Rather than subclass to extend the functionality of an object,
>I think a more modular approach involves implementing the
>extension by USING the original object as part of the "rep".
>
>Borrowing a Smalltalk example, rather than make Dictionary a
>subclass of Set, have Dictionary include a Set as its one
>of its instance variables. ...
This is indeed a good example of where the decision to implement a class
by subclassing a similar existing class or by using the existing class
as an instance variable is not clear-cut. There are situations,
however, in which inheritance is the mechanism of choice. Consider an
abstract class such as Smalltalk's "Link" class, which is used as the
superclass of objects to be placed on "LinkedList"s. It encapsulates
the linkage pointer of its subclasses and permits class LinkedList to be
implemented in a general way so that it can manage a list of any objects
that are subclasses of Link. Class Link serves to allocate the linkage
pointer at a consistent offset in its subclasses and allows class
LinkedList to verify the type of objects being added to the list via the
"isKindOf" method. Simple use of an existing class as an instance
variable of another object does not confer these properties.
>A call to one of these stack procedures would then look like
>
>e = (*Stack_Class.pop)(s);
>...
>is the number of procedures defined. However, this does slow down
>procedure calls because of the selection and de-referencing
>(ignoring possible compiler optimizations).
Both Objective-C and Smalltalk use a search/hash mechanism to locate
class methods, so if you think THIS is slow ...!
Keith Gorlen {decvax!}seismo!elsie!cecil!keith
--
Keith Gorlen {decvax!}seismo!elsie!cecil!keith
More information about the Comp.lang.c
mailing list