# Object Oriented Help

**URL:** <https://rubytalk.org/t/object-oriented-help/42531>\
**Category:** ruby-talk\
**Created:** [27 November 2007 01:03 UTC](https://rubytalk.org/t/object-oriented-help/42531 "2007-11-27T01:03:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Berney](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@Matt\_Berney](https://rubytalk.org/u/Matt_Berney)\
**Post date:** [27 November 2007 01:03 UTC](https://rubytalk.org/t/object-oriented-help/42531/1 "2007-11-27T01:03:57Z")

</div>

We have been using Ruby/Watir for quite some time now. It is a useful  
combination. The object-oriented nature of Ruby with Modules, classes  
and mixins works really well.

Now my dilema...

Currently we have one database object that implements methods for  
customers, payment devices, and sva (Stored Value Accounts).

d = Database.new

d.getCustomerIDByOrder  
d.customerBlacklisted?  
d.customerValidated?

d.getPaymentDeviceByOrder  
d.paymentDeviceBlacklisted?  
d.paymentDeviceValidated?

d.getSvaIDByOrder  
d.svaBlacklisted?  
d.svaValidated?

What is a good way to create an object that publishes common interfaces  
that calls the device specific methods as appropriate?

Something like ...  
getIDByOrder(), blacklisted?(), validated?()

But, how to create the hierarchy to call the appropriate low level  
primitives?

Perhaps have a Customer object, PaymentDevice object, and Sva object  
that each publishes their own interfaces. But, then what next?

TIA

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![A\_LeDonne](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@A\_LeDonne](https://rubytalk.org/u/A_LeDonne)\
**Post date:** [27 November 2007 16:20 UTC](https://rubytalk.org/t/object-oriented-help/42531/2 "2007-11-27T16:20:48Z")

</div>

This is precisely what an ORM (Object Relational Mapper) does, mostly  
automagically. Some of the ORMs I've heard of in Ruby are ActiveRecord  
(used in Rails), Og (used in Nitro), Kansas (used in Iowa), Sequel,  
and DataMapper. I'm sure there are others. A google search for Ruby  
ORM and any of those project names will be very fruitful for you.

Best of luck!

-A

> **···**
>
> On Nov 26, 2007 8:03 PM, Matt Berney \<matt\_watir@hotmail.com\> wrote:
> 
> > We have been using Ruby/Watir for quite some time now. It is a useful  
> > combination. The object-oriented nature of Ruby with Modules, classes  
> > and mixins works really well.
> > 
> > Now my dilema...
> > 
> > Currently we have one database object that implements methods for  
> > customers, payment devices, and sva (Stored Value Accounts).
> > 
> > d = Database.new
> > 
> > d.getCustomerIDByOrder  
> > d.customerBlacklisted?  
> > d.customerValidated?
> > 
> > d.getPaymentDeviceByOrder  
> > d.paymentDeviceBlacklisted?  
> > d.paymentDeviceValidated?
> > 
> > d.getSvaIDByOrder  
> > d.svaBlacklisted?  
> > d.svaValidated?
> > 
> > What is a good way to create an object that publishes common interfaces  
> > that calls the device specific methods as appropriate?
> > 
> > Something like ...  
> > getIDByOrder(), blacklisted?(), validated?()
> > 
> > But, how to create the hierarchy to call the appropriate low level  
> > primitives?
> > 
> > Perhaps have a Customer object, PaymentDevice object, and Sva object  
> > that each publishes their own interfaces. But, then what next?
> > 
> > TIA

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [28 November 2007 09:18 UTC](https://rubytalk.org/t/object-oriented-help/42531/3 "2007-11-28T09:18:20Z")

</div>

Adding to that: Matt, first of all you should separate persistence  
logic from business logic. Your list of sample operations that you  
want to put somewhere indicates that you are about to (or really have  
already) mix those. It's better to keep them separate. Use an ORM  
like Alex suggested for the persistence part and build a proper class  
hierarchy for your application classes. If Customer, PaymentDevice  
and StoredValueAccount have something in common, make them inherit a  
common base class - or create one or more modules that are used by all  
of them.

Kind regards

robert

> **···**
>
> 2007/11/27, Alex LeDonne \<aledonne.listmail@gmail.com\>:
> 
> > On Nov 26, 2007 8:03 PM, Matt Berney \<matt\_watir@hotmail.com\> wrote:  
> > \> We have been using Ruby/Watir for quite some time now. It is a useful  
> > \> combination. The object-oriented nature of Ruby with Modules, classes  
> > \> and mixins works really well.  
> > \>  
> > \> Now my dilema...  
> > \>  
> > \> Currently we have one database object that implements methods for  
> > \> customers, payment devices, and sva (Stored Value Accounts).  
> > \>  
> > \> d = Database.new  
> > \>  
> > \> d.getCustomerIDByOrder  
> > \> d.customerBlacklisted?  
> > \> d.customerValidated?  
> > \>  
> > \> d.getPaymentDeviceByOrder  
> > \> d.paymentDeviceBlacklisted?  
> > \> d.paymentDeviceValidated?  
> > \>  
> > \> d.getSvaIDByOrder  
> > \> d.svaBlacklisted?  
> > \> d.svaValidated?  
> > \>  
> > \> What is a good way to create an object that publishes common interfaces  
> > \> that calls the device specific methods as appropriate?  
> > \>  
> > \> Something like ...  
> > \> getIDByOrder(), blacklisted?(), validated?()  
> > \>  
> > \> But, how to create the hierarchy to call the appropriate low level  
> > \> primitives?  
> > \>  
> > \> Perhaps have a Customer object, PaymentDevice object, and Sva object  
> > \> that each publishes their own interfaces. But, then what next?  
> > \>  
> > \> TIA
> > 
> > This is precisely what an ORM (Object Relational Mapper) does, mostly  
> > automagically. Some of the ORMs I've heard of in Ruby are ActiveRecord  
> > (used in Rails), Og (used in Nitro), Kansas (used in Iowa), Sequel,  
> > and DataMapper. I'm sure there are others. A google search for Ruby  
> > ORM and any of those project names will be very fruitful for you.
> > 
> > Best of luck!
> 
> --  
> use.inject do |as, often| as.you\_can - without end
