Re: [Rails] Re: Class design Help!
On Sat, May 25, 2013 at 11:21 PM, oliver bee <lists@ruby-forum.com> wrote:
> Thanks for the Response Norm, That isn't necessary in this instance
> though (all trucks will have 4 wheels). Should I just keep with what I
> have?
I agree with Norm that this feels inauthentic - objects are typically
used to 'model' real world things and relationships, and I can see
lots of exceptions on your horizon :-)
In any case, I would probably do something like:
class Vehicle
attr_accessor :wheel_count
end
class Truck < Vehicle
def initialize(wheel_count = 4)
@wheel_count = wheel_count
end
end
... and so on.
I'd also recommend 'Practical Object-Oriented Design in Ruby'
( http://www.poodr.info/ ) for some good thoughts on this.
FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
--
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/CACmC4yA%2B5_R9ThVGwj03DFsdSCwj3eP3WhXkubfO4b7qWZ4a2Q%40mail.gmail.com?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