From: Tom Sawyer Date: 2002-07-05T09:40:14+09:00 Subject: Re: self_parent > In this case, wouldn't it be just as simple to make print_label a method of > the Customer class, rather than the Address class? In fact, I would say that > this would be a more logical design, anyway, since one is presumably printing > the label in order to send something to that customer, not just to get > something to that particular address. yes, that's true --always a problem with off the cuff fictions like the example i gave. but the idea of its use is clearer, i hope. but what if both the child and the parent need use of a method that is identical? in such a case you either have to give both classes identical code, which is not very good code reuse. or you have to define a module to mixin to both of them, which is what i do now, even if i only need it for the that one parent and one child. and if you have another child that needs to access a differnt method and yet share it with the parent. well, that's another seperate module to be mixed in, etc. were really talking convience here as obviously one can pass self if need be, currently. ~tom On Thu, 2002-07-04 at 17:42, Harry Ohlsen wrote: > > class Customer > > attr_reader :name, :address > > def initialize(name, address) > > @name = name > > @address = Address.new(address,self) > > end > > def pretty_name > > return @name.upcase > > end > > end > > > > class Address > > def initialize(address, customer) > > @address = address > > @customer = customer > > end > > def print_label > > puts @customer.pretty_name > > puts @address > > end > > end > > > > c = Customer.new("John Doe", "111 Test Ln.\n Santa Fe, NM 87501") > > c.address.print_label > > I understand that this is an invented example that may not show all the issues > involved, but ... > > In this case, wouldn't it be just as simple to make print_label a method of > the Customer class, rather than the Address class? In fact, I would say that > this would be a more logical design, anyway, since one is presumably printing > the label in order to send something to that customer, not just to get > something to that particular address. > > Just a thought and, as I say, may not make sense overall, since you're just > giving us an example here. > > > > -- ~transami "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin