NAYAK
2006-Jun-20 04:14 UTC
[Rails] Achieve pure object oriented design in Ruby (also posted on Ruby List)
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. 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060620/e62df43e/attachment-0001.html
Maybe Matching Threads
- Ruby Scripts in SVG
- [LLVMdev] Regarding LLVM Compiler
- Schema Design: ActiveRecord and Group-Oriented Data
- Having problem with validates_presence_of fields in form when trying to also use ActiveScaffold (x-posted at ActiveScaffold group)
- object-oriented GUI design and event handling