[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

A matter of style.

Graham Nicholls

7/5/2005 3:01:00 PM

I'm writing an application to extract data from a dataease database.

It will have 2 main objects ; an input file and a schema. How would you
organise the code? Would you have a class for each of these objects, and
a function called, say "extract" which would be passed the objects, or
would you have a class called extract which owned the objects "file" &
"schema", and had the method called "extract". Am I barking up the wrong
tree? (Or simply barking?) I hate writing inelegant code - my thinking
being that if I get the top level structure right, the rest is easy. So,
any comments, please.

Thanks
Graham Nicholls
--
The answer's always "Yes".
Now, what was the question?

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.new... The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
4 Answers

Robert Klemme

7/5/2005 3:31:00 PM

0

Graham Nicholls wrote:
> I'm writing an application to extract data from a dataease database.
>
> It will have 2 main objects ; an input file and a schema. How would
> you organise the code? Would you have a class for each of these
> objects, and a function called, say "extract" which would be passed
> the objects, or would you have a class called extract which owned the
> objects "file" & "schema", and had the method called "extract". Am I
> barking up the wrong tree? (Or simply barking?) I hate writing
> inelegant code - my thinking being that if I get the top level
> structure right, the rest is easy. So, any comments, please.

Upfront I'd go with the second alternative (3 classes). That way your
file and schema classes are free to be reused in other contexts and
concerns are nicely separated. Also, extraction seems to be quite a
complex operation that needs some state of its own. Think of the
extractor as an implementaion of the command object pattern.

If any of the three classes is simple (as simple as a file name for
example) then you'd probably want to merge it into the extractor. But
that depends on the complexity and chances for reuse.

Kind regards

robert

Eduardo Yáñez Parareda

7/5/2005 3:36:00 PM

0

> It will have 2 main objects ; an input file and a schema.

You need to ask yourself which of each classes are responsible for
'extract'. If neither 'file' nor
'schema' are responsible for it, then you need a third class.

if a file is owner of an schema then you could ask for him to extract
the schema.


Graham Nicholls

7/5/2005 4:40:00 PM

0

Robert Klemme wrote:

> Graham Nicholls wrote:
>> I'm writing an application to extract data from a dataease database.
>>
>> It will have 2 main objects ; an input file and a schema. How would
>> you organise the code? Would you have a class for each of these
>> objects, and a function called, say "extract" which would be passed
>> the objects, or would you have a class called extract which owned the
>> objects "file" & "schema", and had the method called "extract". Am I
>> barking up the wrong tree? (Or simply barking?) I hate writing
>> inelegant code - my thinking being that if I get the top level
>> structure right, the rest is easy. So, any comments, please.
>
> Upfront I'd go with the second alternative (3 classes). That way your
> file and schema classes are free to be reused in other contexts and
> concerns are nicely separated. Also, extraction seems to be quite a
> complex operation that needs some state of its own. Think of the
> extractor as an implementaion of the command object pattern.
>
> If any of the three classes is simple (as simple as a file name for
> example) then you'd probably want to merge it into the extractor. But
> that depends on the complexity and chances for reuse.
>
> Kind regards
>
> robert
Thanks, both of you. I was beginning to think, yes a third class would be
best, then I decided that really "file" owns a "schema". Then perhaps,
"extract" owns both a file, which as suggested is pretty simple, really,
and a more complex schema. I guess I'll start one way,and simply recode if
it all looks wrong!
Thanks again.
GN
--
The answer's always "Yes".
Now, what was the question?


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.new... The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

james_b

7/5/2005 7:58:00 PM

0

Graham Nicholls wrote:
> I'm writing an application to extract data from a dataease database.
>
> It will have 2 main objects ; an input file and a schema. How would you
> organise the code? Would you have a class for each of these objects, and
> a function called, say "extract" which would be passed the objects, or
> would you have a class called extract which owned the objects "file" &
> "schema", and had the method called "extract". Am I barking up the wrong
> tree? (Or simply barking?) I hate writing inelegant code - my thinking
> being that if I get the top level structure right, the rest is easy. So,
> any comments, please.

Do the simplest thing that works.

James

--

http://www.ru... - The Ruby Documentation Site
http://www.r... - News, Articles, and Listings for Ruby & XML
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys