Object Oriented Help

M

Matt Berney

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
 
A

Alex LeDonne

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!

-A
 
R

Robert Klemme

2007/11/27 said:
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!

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top