johnson@p.cs.uiuc.edu (11/29/88)
>Is it possible to define a subclass that just adds some new methods >(and possibly some new instance variable of its own) to its superClass but >does not duplicate the instance variables of the superClass so that the new >methods access the superClass variables and not the subClass's inheritance of >the variable? It is not possible. The desire to do this is an indication that your class hierarchy needs rearrangement. Example: >My specific application is the development of a simulation >system. If I define a class Simulation with an eventQueue and a current time >and want to define a subClass Entity (objects of a simulation) but I want >Entity to access class Simulation's eventQueue and if possible, have no >eventQueue instance variable. Your problem is that Entity should not be a subclass of Simulation. An Entity is a component of a Simulation, not a subclass. An Arm is not a subclass of Person, and a HeadLight is not a subclass of Car. It is a common mistake to try to make components be subclasses, and this indicates (to me) that there should be better support for components in o-o languages. In this case, each Entity might need to have an instance variable containing the Simulation in which it is used. Maybe you need an abstract class SimulationComponent.