Ruby on Rails
Thursday, March 27, 2014
Hi, thanks for taking the time to respond.
On Thursday, 27 March 2014 01:32:32 UTC+11, Ruby-Forum.com User wrote:
-- I understand the example is a simple one, but based on that simple example, would you agree that since the Car class does not explicitly use the Engine class, the two classes are completely unrelated?
Also, when you say, "Car again becomes more and more coupled to the operations of Engine", are you saying that Car becomes more coupled to the concrete implementation of Engine, or to it's "interface"?
On Thursday, 27 March 2014 01:32:32 UTC+11, Ruby-Forum.com User wrote:
Matthew Riley wrote in post #1141041:
> Hi Rails developers,
>
> I would appreciate some assistance. Please study the following code and
> provide your reasoning for whether you agree or disagree with the
> following
> statements.
>
> I understand the code is not specific to Rails, however I am
> specifically
> interested in Rails developer's perspective. Thanks!
>
> car.rb
>
> class Car
> def initialise(engine)
> @engine = engine
> end
>
> def start
> @engine.start
> end
> end
>
>
> engine.rb
>
> class Engine
>
> def start
>
> puts 'Engine started'
>
> end
>
> end
>
> - Car is not dependent on, and therefore not coupled to Engine
>
> - Car is dependent on an object that responds to "start"
>
> - Car may or may not be initialised with an Engine object
>
> - Car uses constructor-based dependency injection
The example is a little too simple to comment but i can agree with your
statements.
> - Car is dependent on an object that responds to "start".
This i think is the trickiest one. If only the engine class has a method
called 'start' then Car is effectively coupled to Engine. Also if
additional public interface methods get added to Engine, and Car starts
to call those:
engine.gear_up
engine.stop
then Car again becomes more and more coupled to the operations of
Engine.
Also if Car starts to manage other components, and calling their public
interfaces, thus having high fan out, then you also get tight coupling.
So again the point is, this example is still too simple to judge, and
the design pattern that will make the most sense for it is dependent on
how the rest of the application will flow.
--
Posted via http://www.ruby-forum.com/.
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/a170c60e-168c-445d-a80c-e0d24d7b9a11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment