From: Daniel Sheppard Date: 2005-11-02T10:06:27+09:00 Subject: Re: City and Connection The proper answer is that you can implement this a million different ways, depending on the performance needs of your program, the usage of the classes by other objects, the phase of the moon and the degree of bacon in your house. The other answer is: class Connection @@all_connections = [] attr_reader :endpoints def initialize(endpoints) @endpoints = endpoints @@all_connections << self end def all_connections @@all_connections end end class City def connections Connection.all_connections.select do |conn| conn.endpoints.include?(self) end end end The other answer might be wrong though. > -----Original Message----- > From: draq [mailto:boyang.xia@gmail.com] > Sent: Tuesday, 1 November 2005 2:32 AM > To: ruby-talk ML > Subject: City and Connection > > E. g. I am going to make a programm for a forwarding agency > containing two classes: City and Connection. > > The class City contains information about clients, goods etc. > and the class Connection implies the path length, potential > toll charges and type of the road. > > How can I implement the two classes the best? With both > classes referring to each other? > > > > ##################################################################################### This email has been scanned by MailMarshal, an email content filter. #####################################################################################