From: Mat Schaffer Date: 2006-06-20T22:32:49+09:00 Subject: Re: Achieve pure object oriented design in Ruby On Jun 19, 2006, at 9:00 AM, NAYAK wrote: > Hi, > > I have 3 classes A, B and C; I want to achieve following behavior > (I am > calling it "pure object oriented designing") with them. > > 1. An instance of Class C should not exist without instance > of Class B > and instance of Class B should not exist without instance of Class A. > > 2. Class A should be the only class accessible externally, > i.e. one > should not be able to create/modify/delete instances of class B and > class C > outside the scope of class A. > > 3. For modifying member variables of class B and class C, an > external > client should use class A. > > 4. class A has multiple instances of class B associated with > it and > similarly class B has multiple instances of class C associated with > it. > > [snip: example code] > > > Is there any cleaner solution in ruby by which I can achieve above > requirements? I'm a little bummed no-one's tried to answer this. I have no idea how to do it, but the big question in my head is "why?". From a theoretical perspective, encapsulation like this does seems kind of neat. But it sounds like it would make unit testing nearly impossible, which causes some practical issues. For my own curiosity, is this just something you're trying as an exercise? Are you mimicking something that's common practice in another language? -Mat