Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!deimos!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!p.cs.uiuc.edu!johnson From: johnson@p.cs.uiuc.edu Newsgroups: comp.lang.smalltalk Subject: Re: Duplication of instance variables i Message-ID: <80500046@p.cs.uiuc.edu> Date: 28 Nov 88 18:12:00 GMT References: <1397@aucs.UUCP> Lines: 21 Nf-ID: #R:aucs.UUCP:1397:p.cs.uiuc.edu:80500046:000:1288 Nf-From: p.cs.uiuc.edu!johnson Nov 28 12:12:00 1988 >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.