Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!p.cs.uiuc.edu!johnson From: johnson@p.cs.uiuc.edu Newsgroups: comp.lang.c++ Subject: Re: Functions not defined in base class Message-ID: <77300022@p.cs.uiuc.edu> Date: 5 May 89 13:41:00 GMT References: <897@servax0.ESSEX.AC.UK> Lines: 21 Nf-ID: #R:servax0.ESSEX.AC.UK:897:p.cs.uiuc.edu:77300022:000:1056 Nf-From: p.cs.uiuc.edu!johnson May 5 08:41:00 1989 Given the choice of 1) defining a virtual function with a null body in the base class and 2) casting a pointer I would ALWAYS pick 1. One of the characteristic features of an abstract class is that it relies on code that is defined by subclasses. Virtual methods provide this mechanism in C++. Abstract classes are one of the key ideas in object-oriented design and the most important functions in an abstract class are usually the ones that are defined in the subclasses. An abstract class essentially contains the instructions for deriving subclasses from it, because you just define the functions that are left to the subclasses. C++ requires that virtual functions be defined in the base class, so you have to provide a dummy body or the loader will complain. This idea is certainly not specific to C++, but is a feature of all object-oriented languages. In Smalltalk, the base of most large class hierarchies is abstract, such as Collection, Number, and DisplayObject. When it isn't, such as class View, it usually should be. Ralph Johnson