I'm new Ruby but been a .net dev for many a year. I want to implement composition within a couple of my model to make sure they are as loosely coupled as possible but have no idea where to start, or if this is really needed and I'm still thinking to much like a .net dev.
Can anyone give me some pointers on where to start.
Cheers Colin G
Do you mean this sort of thing?
class Engine
attr_reader :horsepower, :litres
end
class Gearbox
attr_reader :manufacturer, :model_no
end
class Car
def initialize(engine, gearbox)
raise "Invalid Engine Object" if !engine.kind_of(Engine)
raise "Invalid Gearbox Object" if !gearbox.kind_of(Gearbox)
@engine = engine
@gearbox = gearbox
end
end
car = Car.new(Engine.new, Gearbox.new)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With