Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!portc02.blue.aol.com!howland.erols.net!EU.net!sun4nl!beta.nedernet.nl!Utrecht.NL.net!mh.nl!argus!news
From: dks@mh.nl (Peter Dekkers)
Subject: Re: Another simple problem..(1)
X-Nntp-Posting-Host: ciao.mh.nl
Content-Type: text/plain; charset=us-ascii
Message-ID: <E16Fuq.4Cp@argus.mh.nl>
Sender: news@argus.mh.nl (ARGUS News Manager)
Organization: Multihouse Automatisering b.v.
X-Newsreader: knews 0.9.7
References: <56r4m7$5uu@mn5.swip.net>
Mime-Version: 1.0
Date: Wed, 20 Nov 1996 16:16:02 GMT
Lines: 47

In article <56r4m7$5uu@mn5.swip.net>,
	henrik.brinkhagen@mailbox.swipnet.se (Henrik Brinkhagen) writes:
> Hi there!
> 
> I have this problem I need advice on. 
> 
> Assume we have three classes (A,B,C) which all have a common superclass 
> (for example Object).
> 
> Each class has, at least, one instance variable which is a container.
> 
> The content of A:s container is B. The content of B:s container is C.
> 
> What I am trying to say is something like: 
> 
> 	
> A is a house with appartments (B). Each appartment has rooms (C). We have an in 
> some way "nestled" relation.
> 
> My question is then: How do I write instance methods in A dealing with 
> information in C?
> 
> In other words: How do I write a method which returns the number of rooms 
> (instances of C) in a given house (instance of A)??
> 
> I have no problem writing a method in A returning the number of instances of B 
> (i e how many appartments in a particular house) or a method in B returning the 
> number of instances of C (how many rooms in a particular appartment). The 
> problems occur when I have to go from A to C via B !!
> 
> All advice most greatly appreciated!!
> 
> Thanx!
> /Henrik
> 

If you have written a method in B returning the number of rooms ( lets call
it size and appartments being the inst var in class A ) you can do 
something like:

| totalRooms |
totalRooms := 0.
appartments do: [ :anAppartment | totalRooms := totalRooms + ( B size ) ].
^ totalRooms
 
Or do the same with inject.

