Saturday, May 25, 2013

Re: [Rails] Class design Help!

Maybe you have a particular limited set of vehicles but trucks I know
have from 4 to 10 (or more) wheels and motorcycles have 2 or 3 wheels
and Semi-trailer trucks have 10 to 20 (or more) wheels depending on
application. I would store the number of wheels in the database.

Norm

On 05/24/2013 11:40 PM, oliver bee wrote:
> I have 3 classes ("Truck", "Semi", "Motorcycle") that all inherit from
> the "Vehicle" class.
> Each subclass has an attribute for "Wheels" that tells how many wheels
> the vehicle has (I do not store these values in the database because
> they will never change)
>
> I'm wondering what is the preferred method for handling this? Right now
> I have individual methods in each class for "Wheels":
>
> For example:
>
> class Truck
> def wheels
> 4
> end
> end
>
> class Motorcycle
> def wheels
> 2
> end
> end
>
> class Semi
> def wheels
> 18
> end
> end
>
> Is there a better way??? Thanks
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/51A105F0.50100%40earthlink.net?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate