# Object Oriented Help

**URL:** <https://www.ruby-forum.com/t/object-oriented-help/121344>\
**Category:** Ruby\
**Created:** [November 27, 2007, 2:04am UTC](https://www.ruby-forum.com/t/object-oriented-help/121344 "2007-11-27T02:04:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![burrowsm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@burrowsm](https://www.ruby-forum.com/u/burrowsm)\
**Post date:** [November 27, 2007, 2:04am UTC](https://www.ruby-forum.com/t/object-oriented-help/121344/1 "2007-11-27T02:04:00Z")

</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

---

<div class="post-metadata">

**Author:** ![burrowsm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@burrowsm](https://www.ruby-forum.com/u/burrowsm)\
**Post date:** [November 27, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/object-oriented-help/121344/2 "2007-11-27T17:21:41Z")

</div>

On Nov 26, 2007 8:03 PM, Matt B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> d.svaValidated?  
> 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!

-A

---

<div class="post-metadata">

**Author:** ![burrowsm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@burrowsm](https://www.ruby-forum.com/u/burrowsm)\
**Post date:** [November 28, 2007, 10:19am UTC](https://www.ruby-forum.com/t/object-oriented-help/121344/3 "2007-11-28T10:19:52Z")

</div>

2007/11/27, Alex LeDonne [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > d = Database.new  
> > d.svaBlacklisted?
> 
> ORM and any of those project names will be very fruitful for you.
> 
> Best of luck!

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
