Forum: Ruby Design question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Srijayanth S. (Guest)
on 2009-05-06 17:05
(Received via mailing list)
Hello,

I am building a simple tool to help with some statistical analysis of a
sports site. I have the following:

class Player # just a wrapper around ostruct for read_only access
class Team # a collection of players
class League # a collection of teams

There are many ways I can "build" the league so to speak. I want to be
able
to build the league from a web site(scraping for information), from a
DB(for
local access) and a file(for even more local access I suppose). Now I am
having a bit of a problem organizing a few things.

Should I have an abstract class Builder and derive WebBuilder,
DBBuilder,
and FileBuilder from it or should I just have different methods within
the
league class? If I were to make these separate classes, then the builder
class will have to somehow get the data back across to the League class
which actually builds the team. It feels a bit kludgy. I don't want to
burden the Team and Player's constructors with any more than just basic
assignments. Is this a bad idea?

And the bigger fish here is the web builder. The web builder has to
screen
scrape a site with a list of teams, from which it goes to each team
page,
and further fetches statistics by going to the player's site. Its really
elementary to do, but again, where should it ideally fit?

Thank you,

Jayanth
Robert K. (Guest)
on 2009-05-06 18:32
(Received via mailing list)
2009/5/6 Srijayanth S. <removed_email_address@domain.invalid>:
> having a bit of a problem organizing a few things.
>
> Should I have an abstract class Builder and derive WebBuilder, DBBuilder,
> and FileBuilder from it or should I just have different methods within the
> league class?

Definitively decouple the stuff into several other classes and do not
do it with a bunch of methods!

> If I were to make these separate classes, then the builder
> class will have to somehow get the data back across to the League class
> which actually builds the team. It feels a bit kludgy. I don't want to
> burden the Team and Player's constructors with any more than just basic
> assignments. Is this a bad idea?
>
> And the bigger fish here is the web builder. The web builder has to screen
> scrape a site with a list of teams, from which it goes to each team page,
> and further fetches statistics by going to the player's site. Its really
> elementary to do, but again, where should it ideally fit?

From what you write I conclude (although not 100% sure) that you have
read only access to all the data storage variants (at least for web
this sounds reasonable).  This is certainly a point that needs
clarification.

Note, I haven't used ActiveRecord so far but I would probably use that
(or any other OO mapper) to do the DB binding.  Then I'd try to model
the file and web bindings with a similar interface.  Dunno whether
this is feasible but at least worth exploring.

Kind regards

robert
This topic is locked and can not be replied to.