Object Oriented Help

Discussion in 'Ruby' started by Matt Berney, Nov 27, 2007.

  1. Matt Berney

    Matt Berney Guest

    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/.
     
    Matt Berney, Nov 27, 2007
    #1
    1. Advertising

  2. Matt Berney

    Alex LeDonne Guest

    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
     
    Alex LeDonne, Nov 27, 2007
    #2
    1. Advertising

  3. 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
     
    Robert Klemme, Nov 28, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Hathaway
    Replies:
    0
    Views:
    420
    Robert Hathaway
    Jul 29, 2003
  2. Robert Hathaway
    Replies:
    0
    Views:
    422
    Robert Hathaway
    Jul 29, 2003
  3. Robert Hathaway
    Replies:
    1
    Views:
    459
    Robert J Hathaway III
    Jul 29, 2003
  4. Replies:
    2
    Views:
    429
    Bruno Desthuilliers
    May 26, 2008
  5. rolo
    Replies:
    3
    Views:
    174
    Robert Klemme
    Apr 9, 2004
Loading...

Share This Page