Article View: comp.lang.clos
Article #208Re: Implementation Question
From: Graham Matthews
Date: Wed, 02 Sep 1992 23:58
Date: Wed, 02 Sep 1992 23:58
68 lines
3282 bytes
3282 bytes
Graham: > I was wondering about a small implementation problem I am having. > Imagine I have two classes A and B defined as follows, > > class A > instance variables a, b, c; > end class; > > class B > subclass of class A; > instance variables e, f; > end class; > > (by "instance variable" i mean that an instance of class A will > have three "fields"/"slots" (pick your terminology!) named a, b and > c). > > Now my problem is as follows. How do OO implentations handle the > space allocation for an instance of class B? Does an instance of B > have to have space allocated for all the instance variables in B as > well as all the instance variables in all the classes of which B is > a sub-class (in this case class A). I ask this for three reasons :- > > a) I have many examples where B is a subclass of A but one rarely > utilises this feature. All the time is spent computing with instances > of B as instances of the sub-class B and not as instances of the > super-class A. So I do not want to allocate space for any instance > variables (in this case those in class A) which I am rarely if ever > going to use. kanderso@bbn.com writes: >But there must be some A behavior that B needs, otherwise B would not need >to be a subclass of A. It sounds like you want your B class to inherit >from a class "essential A" which has the A behavior you need, without the slots. No not really. The example I have in mind is a module and an abelian group. Now a module *is* an abelian group, but one hardly ever computes with it as such - users are aware of the is-a relationship but hardly ever make any use of it. They always want to compute with modules and sub-types of it such as vector spaces, and are not at all interested in its abelian group structure. graham > b) I have example code where the representation of B is not the > same as A. That is mathematically B is a sub-type of A but for > various reasons the implementation of B does not have any of the > slots of A. > kanderso@bbn.com writes: >You can separate the "mathematical subtypeness" from implementation using >a level of indirection: >class A > instance variables implementation; >end class; >class B > subclass of A; >end class; >A's and B's can forward to an object in instance variable implementation >that implements the real behavior. I am not sure I understand what you mean here. What do you mean by "forward to an object in instance variable implementation"? graham -- Graham Matthews And it's true we are immune Pure Math, Uni.Sydney, Oz When fact is fiction and T.V. is reality graham@maths.su.oz.au
Technical Details
Message-ID:
<graham.715478284@galois>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!mel.dit.csiro.au!mineng.dmpe.CSIRO.AU!dmssyd.syd.dms.CSIRO.AU!metro!grahamReferences:
<graham.715435125@galois> <9209021511.AA29151@news.cis.ohio-state.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!mel.dit.csiro.au!mineng.dmpe.CSIRO.AU!dmssyd.syd.dms.CSIRO.AU!metro!graham From: graham@maths.su.oz.au (Graham Matthews) Subject: Re: Implementation Question Message-ID: <graham.715478284@galois> Sender: graham@maths.su.oz.au Nntp-Posting-Host: galois.maths.su.oz.au Organization: School of Mathematics and Statistics, University of Sydney References: <graham.715435125@galois> <9209021511.AA29151@news.cis.ohio-state.edu> Date: Wed, 2 Sep 1992 23:58:04 GMT Lines: 68