<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:series="http://organizeseries.com/"
		>
<channel>
	<title>Comments on: Q&amp;A: Answering Some Questions About Object-Oriented Programming</title>
	<atom:link href="http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=qa-answering-some-questions-about-object-oriented-programming</link>
	<description>The personal blog of Brandon Savage. Contains entries of a personal and professional nature focusing on PHP, Apple, LAMP, MySQL and Washington, DC.</description>
	<lastBuildDate>Wed, 15 May 2013 14:54:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2-alpha</generator>
	<item>
		<title>By: Rory</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1831</link>
		<dc:creator>Rory</dc:creator>
		<pubDate>Sat, 31 Oct 2009 18:30:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1831</guid>
		<description><![CDATA[I would agree with Richard. If you&#039;re object has more than (for example) 5 dependencies it&#039;s probably doing too much. DI lets you recognize this so you can narrow the foccus of your objects.

In terms of instantiation, you are just moving the creation logic somewhere else but that is the whole point. The business of creating objects is separated from the normal work of the objects themselves. That is the specific goal. If you can&#039;t find any benefit in that then DI is not for you.]]></description>
		<content:encoded><![CDATA[<p>I would agree with Richard. If you&#8217;re object has more than (for example) 5 dependencies it&#8217;s probably doing too much. DI lets you recognize this so you can narrow the foccus of your objects.</p>
<p>In terms of instantiation, you are just moving the creation logic somewhere else but that is the whole point. The business of creating objects is separated from the normal work of the objects themselves. That is the specific goal. If you can&#8217;t find any benefit in that then DI is not for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Lynch</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1824</link>
		<dc:creator>Richard Lynch</dc:creator>
		<pubDate>Sat, 31 Oct 2009 05:04:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1824</guid>
		<description><![CDATA[I would assume that a car might take a few parameters:
engine
body
chassis

The body would take in various subsystems, as would the engine and chassis.

Anything with more than a handful of parameters is just a pain to use.

It all depends, pun intended, on what your application has to actually DO with a &quot;car&quot;.]]></description>
		<content:encoded><![CDATA[<p>I would assume that a car might take a few parameters:<br />
engine<br />
body<br />
chassis</p>
<p>The body would take in various subsystems, as would the engine and chassis.</p>
<p>Anything with more than a handful of parameters is just a pain to use.</p>
<p>It all depends, pun intended, on what your application has to actually DO with a &#8220;car&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob...</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1822</link>
		<dc:creator>Rob...</dc:creator>
		<pubDate>Sat, 31 Oct 2009 01:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1822</guid>
		<description><![CDATA[Rory,

Are you really suggesting that the Car&#039;s constructor takes an instance of: Engine, Wheels, Seats, Drivetrain, ExhaustSystem, Electrics, etc. ?

What does the object that instantiates the Car look like?

Whilst pushing the decision up the chain can help, at the end of the day we need to write perfomant apps that can be maintained long term by people that didn&#039;t write the original system. 90% of the time it&#039;s gonna be fine to let the engine decide what type of pistons it needs. We just need to be able to override the default choice (usually for testing parts in isolation).


Regards,

Rob....]]></description>
		<content:encoded><![CDATA[<p>Rory,</p>
<p>Are you really suggesting that the Car&#8217;s constructor takes an instance of: Engine, Wheels, Seats, Drivetrain, ExhaustSystem, Electrics, etc. ?</p>
<p>What does the object that instantiates the Car look like?</p>
<p>Whilst pushing the decision up the chain can help, at the end of the day we need to write perfomant apps that can be maintained long term by people that didn&#8217;t write the original system. 90% of the time it&#8217;s gonna be fine to let the engine decide what type of pistons it needs. We just need to be able to override the default choice (usually for testing parts in isolation).</p>
<p>Regards,</p>
<p>Rob&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1821</link>
		<dc:creator>Les</dc:creator>
		<pubDate>Fri, 30 Oct 2009 23:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1821</guid>
		<description><![CDATA[Whilst I understand the hows and whys of Dependency Injections it&#039;s not something I&#039;ve been fully supportive of implementing - I&#039;m not convinced it&#039;s an ideal solution.

Seams to me it&#039;s top heavy even for larger application development; my opinion is that you can achieve much the same effect solely with Factories - in which case you simply swap out factories.

I am of the feeling we need to streamline an applications foot print and most DI solutions are additional bloat - and do remember whatever solution you do use that in it&#039;s self is a dependency.

To close, I am also left with the impression that many developers want to or would wish to implement DI as a way around the after affects of poor design thinking that they are safe from it&#039;s [DI] use.

The use of any DI solution does not solve nor excuse issues brought upon by poor design.]]></description>
		<content:encoded><![CDATA[<p>Whilst I understand the hows and whys of Dependency Injections it&#8217;s not something I&#8217;ve been fully supportive of implementing &#8211; I&#8217;m not convinced it&#8217;s an ideal solution.</p>
<p>Seams to me it&#8217;s top heavy even for larger application development; my opinion is that you can achieve much the same effect solely with Factories &#8211; in which case you simply swap out factories.</p>
<p>I am of the feeling we need to streamline an applications foot print and most DI solutions are additional bloat &#8211; and do remember whatever solution you do use that in it&#8217;s self is a dependency.</p>
<p>To close, I am also left with the impression that many developers want to or would wish to implement DI as a way around the after affects of poor design thinking that they are safe from it&#8217;s [DI] use.</p>
<p>The use of any DI solution does not solve nor excuse issues brought upon by poor design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rory</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1820</link>
		<dc:creator>Rory</dc:creator>
		<pubDate>Fri, 30 Oct 2009 23:04:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1820</guid>
		<description><![CDATA[@Rob - Just to clarify - a Car doesn&#039;t need to know about Pistons at all because you inject the (already created) Engine into the Car

class Car {

public function __construct(Engine $engine) {

You don&#039;t need your car worrying about how to create it&#039;s own engine.]]></description>
		<content:encoded><![CDATA[<p>@Rob &#8211; Just to clarify &#8211; a Car doesn&#8217;t need to know about Pistons at all because you inject the (already created) Engine into the Car</p>
<p>class Car {</p>
<p>public function __construct(Engine $engine) {</p>
<p>You don&#8217;t need your car worrying about how to create it&#8217;s own engine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Herman Radtke</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1818</link>
		<dc:creator>Herman Radtke</dc:creator>
		<pubDate>Fri, 30 Oct 2009 20:55:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1818</guid>
		<description><![CDATA[@Ivo Here are my guidelines for constructor vs setter DI: 

Constructor injection is generally used when the injected dependency will last the lifetime of the object or the dependency requires injection in a certain order.  
Setter injection is generally used if the injected dependency has a lifetime shorter than the object it is passed into.]]></description>
		<content:encoded><![CDATA[<p>@Ivo Here are my guidelines for constructor vs setter DI: </p>
<p>Constructor injection is generally used when the injected dependency will last the lifetime of the object or the dependency requires injection in a certain order.<br />
Setter injection is generally used if the injected dependency has a lifetime shorter than the object it is passed into.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Hochdoerfer</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1816</link>
		<dc:creator>Stephan Hochdoerfer</dc:creator>
		<pubDate>Fri, 30 Oct 2009 13:57:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1816</guid>
		<description><![CDATA[@Ivo: I`d prefer constructor based injection since it automatically enforces the completeness of the instantiated object. With setter based injection it is not clear in which order things need to be instantiated and wired together.

And since I hope you use some kind of DI container that automatically does the wiring for you (e.g. based on some kind of configuration file), it should basically not matter how the wiring is done.]]></description>
		<content:encoded><![CDATA[<p>@Ivo: I`d prefer constructor based injection since it automatically enforces the completeness of the instantiated object. With setter based injection it is not clear in which order things need to be instantiated and wired together.</p>
<p>And since I hope you use some kind of DI container that automatically does the wiring for you (e.g. based on some kind of configuration file), it should basically not matter how the wiring is done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brandon Savage</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1814</link>
		<dc:creator>Brandon Savage</dc:creator>
		<pubDate>Fri, 30 Oct 2009 09:33:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1814</guid>
		<description><![CDATA[The assumption was that an engine will always need a radiator (though not always true in real life, as Volkswagen and Porsche showed). If we were to abstract this as a programming technique rather than a car part, we might see that the Controller needs a Request, a ResponseFormatter and an Action to complete.

With regards to where the engine is constructed, I would make the assumption (and the practical choice) of building a Factory where the Engine is constructed and then placed into the Car along with the Car&#039;s other components (Wheels, Brakes, Transmission, etc.). While Rob is right in that I did not show that a consumer of an Engine would not need to know how an Engine works, my example was far from feature complete and a fully feature complete example would have been nearly impossible.

I do appreciate the comments, and I merit in each approach.]]></description>
		<content:encoded><![CDATA[<p>The assumption was that an engine will always need a radiator (though not always true in real life, as Volkswagen and Porsche showed). If we were to abstract this as a programming technique rather than a car part, we might see that the Controller needs a Request, a ResponseFormatter and an Action to complete.</p>
<p>With regards to where the engine is constructed, I would make the assumption (and the practical choice) of building a Factory where the Engine is constructed and then placed into the Car along with the Car&#8217;s other components (Wheels, Brakes, Transmission, etc.). While Rob is right in that I did not show that a consumer of an Engine would not need to know how an Engine works, my example was far from feature complete and a fully feature complete example would have been nearly impossible.</p>
<p>I do appreciate the comments, and I merit in each approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivo</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1812</link>
		<dc:creator>Ivo</dc:creator>
		<pubDate>Fri, 30 Oct 2009 08:47:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1812</guid>
		<description><![CDATA[The article you link to actually explains very well why setter based injection is better than constructor based injection, and it has a nice alternative way using factories:

http://www.potstuck.com/2009/01/08/php-dependency-injection/]]></description>
		<content:encoded><![CDATA[<p>The article you link to actually explains very well why setter based injection is better than constructor based injection, and it has a nice alternative way using factories:</p>
<p><a href="http://www.potstuck.com/2009/01/08/php-dependency-injection/" rel="nofollow">http://www.potstuck.com/2009/01/08/php-dependency-injection/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivo</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1811</link>
		<dc:creator>Ivo</dc:creator>
		<pubDate>Fri, 30 Oct 2009 08:42:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1811</guid>
		<description><![CDATA[Yes, Rob&#039;s point is valid. You&#039;re not taking dependency out of the system, you&#039;re moving it up. If the engine is optimized to no longer need a radiator, consumers are still passing you a useless radiator. Rob and Brandon, What do you think of these alternative way to inject the dependency?

class Engine
{
  protected $radiator;

  public function setRadiator(RadiatorI $r) {
      $this-&gt;radiator = $r;
  }

  public function getRadiator() {
      if (!$this-&gt;radiator) $this-&gt;radiator = new
          DefaultRadiator();
      return $this-&gt;radiator;
  }
}

This variant allows use of the engine without knowing it even has a radiator; however, consumers that are savvy about such things can still inject their own radiator.

Variant 2:

class Engine
{
  protected $parts;

  public function __construct(Parts $p) { 
      $this-&gt;parts = $p;
  }

  ... // code that needs a radiator.
  $radiator = $this-&gt;parts-&gt;getRadiator();
}

// In this case, Parts can act like a broker that injects those objects that are necessary, and apps can tell the broker they want a specific radiator to be used whenever someone requests it.

(e.g. Government calls $parts-&gt;setRadiator(new EcoFriendlyRadiator());]]></description>
		<content:encoded><![CDATA[<p>Yes, Rob&#8217;s point is valid. You&#8217;re not taking dependency out of the system, you&#8217;re moving it up. If the engine is optimized to no longer need a radiator, consumers are still passing you a useless radiator. Rob and Brandon, What do you think of these alternative way to inject the dependency?</p>
<p>class Engine<br />
{<br />
  protected $radiator;</p>
<p>  public function setRadiator(RadiatorI $r) {<br />
      $this-&gt;radiator = $r;<br />
  }</p>
<p>  public function getRadiator() {<br />
      if (!$this-&gt;radiator) $this-&gt;radiator = new<br />
          DefaultRadiator();<br />
      return $this-&gt;radiator;<br />
  }<br />
}</p>
<p>This variant allows use of the engine without knowing it even has a radiator; however, consumers that are savvy about such things can still inject their own radiator.</p>
<p>Variant 2:</p>
<p>class Engine<br />
{<br />
  protected $parts;</p>
<p>  public function __construct(Parts $p) {<br />
      $this-&gt;parts = $p;<br />
  }</p>
<p>  &#8230; // code that needs a radiator.<br />
  $radiator = $this-&gt;parts-&gt;getRadiator();<br />
}</p>
<p>// In this case, Parts can act like a broker that injects those objects that are necessary, and apps can tell the broker they want a specific radiator to be used whenever someone requests it.</p>
<p>(e.g. Government calls $parts-&gt;setRadiator(new EcoFriendlyRadiator());</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob...</title>
		<link>http://www.brandonsavage.net/qa-answering-some-questions-about-object-oriented-programming/#comment-1810</link>
		<dc:creator>Rob...</dc:creator>
		<pubDate>Fri, 30 Oct 2009 07:01:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=963#comment-1810</guid>
		<description><![CDATA[Whilst you have shown benefits to Engine of injecting the Pistons, Crankshaft and Radator into it, you haven&#039;t shown how to avoid having a consumer of an Engine having to know too much detail about how an engine is made up.

e.g. if I have class Car that uses an Engine, the car now needs to know about Pistons etc. At the car level of abstraction, you may want to swap in different types of engine (e.g. remove a petrol one and replace with an electric one) without having to worry about the type of pistons the new engine uses.

I think it would be beneficial to provide some discussion on the practical ways to instantiate an object like this. Obviously a DI system like Pico is one way, or a factory function could also be used.

Regards,

Rob...]]></description>
		<content:encoded><![CDATA[<p>Whilst you have shown benefits to Engine of injecting the Pistons, Crankshaft and Radator into it, you haven&#8217;t shown how to avoid having a consumer of an Engine having to know too much detail about how an engine is made up.</p>
<p>e.g. if I have class Car that uses an Engine, the car now needs to know about Pistons etc. At the car level of abstraction, you may want to swap in different types of engine (e.g. remove a petrol one and replace with an electric one) without having to worry about the type of pistons the new engine uses.</p>
<p>I think it would be beneficial to provide some discussion on the practical ways to instantiate an object like this. Obviously a DI system like Pico is one way, or a factory function could also be used.</p>
<p>Regards,</p>
<p>Rob&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced (User agent is rejected)
Object Caching 601/622 objects using apc
Content Delivery Network via Amazon Web Services: S3: brandonsavage-net-files.s3.amazonaws.com

 Served from: www.brandonsavage.net @ 2013-05-21 20:15:48 by W3 Total Cache -->