From: Mario Camou Date: 2009-08-11T22:39:51+09:00 Subject: Re: Destroying related objects doubt ... basic oop question --0016369fa2ca2bd99e0470ddbb17 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Tue, Aug 11, 2009 at 13:57, 7stud -- wrote: > Soh Dubom wrote: > > ex.: let's say we have objects House and Rooms, the relationship between > > them is composition, so House is responsible for creating new Rooms. If > > I destroy the instance of House, all instances of Rooms will be > > destroyed as well, > > Really? > > class House > def initialize(room) > @room = room > end > end > > class Room > def show > puts "I'm a room." > end > end > > r = Room.new > h = House.new(r) > h = nil > > r.show > > --output:-- > I'm a room. > -- > Posted via http://www.ruby-forum.com/. > > That's not composition. In a composition relationship the House class is responsible for managing the Room class and you can't pass in a Room to the House constructor -Mario. -- I want to change the world but they won't give me the source code. --0016369fa2ca2bd99e0470ddbb17--