# Achieve pure object oriented design in Ruby (also posted on

**URL:** <https://www.ruby-forum.com/t/achieve-pure-object-oriented-design-in-ruby-also-posted-on/63888>\
**Category:** Rails\
**Created:** [June 20, 2006, 11:11am UTC](https://www.ruby-forum.com/t/achieve-pure-object-oriented-design-in-ruby-also-posted-on/63888 "2006-06-20T11:11:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nayak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/90ced4/32.png) [@nayak](https://www.ruby-forum.com/u/nayak)\
**Post date:** [June 20, 2006, 11:11am UTC](https://www.ruby-forum.com/t/achieve-pure-object-oriented-design-in-ruby-also-posted-on/63888/1 "2006-06-20T11:11:11Z")

</div>

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.

1. 

```
   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.

1. 

```
   For modifying member variables of class B and class C, an 

```

external  
client should use class A.

1. 

```
   class A has multiple instances of class B associated with it 

```

and  
similarly class B has multiple instances of class C associated with it.

Following are the classes with required methods and variables;

class A

#array of objects of class B associated with this instance

```
        @b_objs

```

#method to create instance of B and add it to above array

#methods to modify member variables of an instance of B and C (class C  
is  
defined below)

end

class B

@b1

@b2

#array of objects of class C

```
        @c_objs

```

#method to create instance of C and add it to above array

#methods to modify member variables of an instance of C

end

class C

@c1

```
        @c2

```

end

How would I achieve 4 points listed above?

One solution I thought was to have nested classes as below,

Class A

Class B

```
        Class C

        end

```

end

end

above approach satisfies all the points, but for point 3 above(For  
modifying  
member variables of class B and class C, an external client should use  
class  
A), there would be an overhead of adding a large number of wrapper  
methods  
for members of classes B and C.

Is there any cleaner solution in ruby by which I can achieve above  
requirements?  
Thanks in Advance,  
NAYAK
