Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Object Oriented Help

Reply
Thread Tools

Object Oriented Help

 
 
Matt Berney
Guest
Posts: n/a
 
      11-27-2007
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/.

 
Reply With Quote
 
 
 
 
Alex LeDonne
Guest
Posts: n/a
 
      11-27-2007
On Nov 26, 2007 8:03 PM, Matt Berney <> 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!

-A

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-28-2007
2007/11/27, Alex LeDonne <>:
> On Nov 26, 2007 8:03 PM, Matt Berney <> 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!


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

--
use.inject do |as, often| as.you_can - without end

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class-oriented rather than object-oriented? notnorwegian@yahoo.se Python 2 05-26-2008 04:42 PM
Object oriented does not mean class oriented rolo Ruby 3 04-09-2004 02:51 PM
Comp.Object FAQ - Version II Beta - Latest Object Oriented Resource - Please Participate! Robert Hathaway C++ 1 07-29-2003 12:44 PM
Comp.Object FAQ - Version II Beta - Latest Object Oriented Resource - Please Participate! Robert Hathaway Java 0 07-29-2003 04:50 AM
Comp.Object FAQ - Version II Beta - Latest Object Oriented Resource - Please Participate! Robert Hathaway Java 0 07-29-2003 04:42 AM



Advertisments