I noted in your earlier email you said you were fairly new to Ruby, so it could 
be that one of your designs goals is solved by a different Ruby feature.

Say you have several models that all need to have a #to_duck method, and that 
the method definition is exactly the same for each model. You might think that 
this is a case for inheritance, but in Ruby, you have another option. Instead 
of defining #to_duck in a parent class and subclasses your models, you can 
define #to_duck in a module and include that module into the classes 
definitions of the models that need it.

Here's a reasonable humorous and easy to understand rundown of how to use 
modules this way:
<http://www.rubyfleebie.com/an-introduction-to-modules-part-2/>

This way you are keeping your code DRY, but avoiding the pitfalls of STI. My 
personal opinion is you should only use STI if the properties are an exact or 
near-exact match. Otherwise you start down a rabbit hole from which you may 
never return.

-Sean

On Thursday 10 September 2009 8:08:42 am Jos Elkink wrote:
> Hi all,
> 
> I just posted a technical question, but I also have a more general design
> question, that is probably not really specific to DataMapper.
> 
> I have a set of classes along the following lines:
> 
> class Item
> end
> 
> class Note < Item
> class Knife < Item
> 
> etc. etc.
> 
> This can become quite a long list. Since they are single table inheritance,
> all the information ends up in one SQL table. I.e. notes have titles and
> contents, which means that now every item (incl. e.g. knives) have a "title"
> and "content" field. Not in the class definition, of course, but in the SQL
> table.
> 
> My simple question is: is this bad design? Does this lead to super
> inefficient database usage? Or is this just fine and common?
> 
> In terms of practical usage and coding, the inheritance definitely brings
> substantial benefits.
> 
> Jos
> 
> > 
> 

-- 
Sean Kellogg
e: [email protected]
w: http://blog.probonogeek.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to