<?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/"
		>
<channel>
	<title>Comments on: The Three Reasons for Data Encapsulation</title>
	<atom:link href="http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/</link>
	<description>Longer than a blog; shorter than a book</description>
	<lastBuildDate>Wed, 08 Feb 2012 21:45:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Black pinstripe suit</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-779337</link>
		<dc:creator>Black pinstripe suit</dc:creator>
		<pubDate>Sat, 27 Aug 2011 06:41:32 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-779337</guid>
		<description>Sorry, I dont have much time to say why cause Im in a hurry and happen to read your post, nonetheless i feel I have to write you that I strongly disagree with you. Ill come back and explain myself better later. Cheers -instantempo</description>
		<content:encoded><![CDATA[<p>Sorry, I dont have much time to say why cause Im in a hurry and happen to read your post, nonetheless i feel I have to write you that I strongly disagree with you. Ill come back and explain myself better later. Cheers -instantempo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: why do dogs eat poop</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-719023</link>
		<dc:creator>why do dogs eat poop</dc:creator>
		<pubDate>Thu, 30 Jun 2011 07:06:43 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-719023</guid>
		<description>My good friend normally linked me to this web-site unfortunately this is actually the very first post I had checked out up to now. Im quite fascinated and so now a fan.</description>
		<content:encoded><![CDATA[<p>My good friend normally linked me to this web-site unfortunately this is actually the very first post I had checked out up to now. Im quite fascinated and so now a fan.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: upper east side apartments</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-715832</link>
		<dc:creator>upper east side apartments</dc:creator>
		<pubDate>Mon, 27 Jun 2011 02:17:30 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-715832</guid>
		<description>Was actually doing a search and came across this site. I must say that this info is on point! Keep writing more. I will be following your sites</description>
		<content:encoded><![CDATA[<p>Was actually doing a search and came across this site. I must say that this info is on point! Keep writing more. I will be following your sites</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: miles zarathustra</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-473850</link>
		<dc:creator>miles zarathustra</dc:creator>
		<pubDate>Wed, 07 Apr 2010 02:59:16 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-473850</guid>
		<description>This is precisely why I dislike dependency injection - by forcing a public getter and setter, it essentially forces all of your fields to be public.  True, one can enforce limits in the &#039;set&#039; method, but nobody ever seems to bother.  After all, who has the time to meddle with each of the overwhelming myriad of get and set methods generated by the IDE?

My personal preference is to enforce immutablilty when possible (by only setting from the constructor) and then limiting the number of fields with public &#039;set&#039; methods to those strictly required.

Just my take on it, YMMV.  :-) 

-= miles =-</description>
		<content:encoded><![CDATA[<p>This is precisely why I dislike dependency injection &#8211; by forcing a public getter and setter, it essentially forces all of your fields to be public.  True, one can enforce limits in the &#8216;set&#8217; method, but nobody ever seems to bother.  After all, who has the time to meddle with each of the overwhelming myriad of get and set methods generated by the IDE?</p>
<p>My personal preference is to enforce immutablilty when possible (by only setting from the constructor) and then limiting the number of fields with public &#8216;set&#8217; methods to those strictly required.</p>
<p>Just my take on it, YMMV.  <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>-= miles =-</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kislay</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-472230</link>
		<dc:creator>Kislay</dc:creator>
		<pubDate>Tue, 30 Mar 2010 05:12:27 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-472230</guid>
		<description>Hi J H ,
As you said &quot;If you make an object public instead of providing a get and set, then you can never change the object without affecting external users.&quot;  Can you please explain this in programming way. I am not able to understand what you are trying to say.
Please explain bit more .

Thanks</description>
		<content:encoded><![CDATA[<p>Hi J H ,<br />
As you said &#8220;If you make an object public instead of providing a get and set, then you can never change the object without affecting external users.&#8221;  Can you please explain this in programming way. I am not able to understand what you are trying to say.<br />
Please explain bit more .</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J H</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-451614</link>
		<dc:creator>J H</dc:creator>
		<pubDate>Tue, 15 Dec 2009 05:16:38 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-451614</guid>
		<description>Aaron,
  Answering your comment is an act of necromancy, but your comment was, too, so:
  If you make an object public instead of providing a get and set, then you can never change the object without affecting external users.  You could say &quot;so what&quot; to that, but your software may undergo many revisions including changing the way data is organized.  Right now the public object might be a stand-alone float, tomorrow you might want to put it into a record, etc..  As long as you don&#039;t rename the get and set, you can change your objects&#039; names without affecting others.
  That is the real value of encapsulation:  not &quot;hiding&quot; what you have or do from the eyes of other developers, just ensuring independence of development.  It&#039;s not a rule, it&#039;s a benefit to be weighed against its costs.</description>
		<content:encoded><![CDATA[<p>Aaron,<br />
  Answering your comment is an act of necromancy, but your comment was, too, so:<br />
  If you make an object public instead of providing a get and set, then you can never change the object without affecting external users.  You could say &#8220;so what&#8221; to that, but your software may undergo many revisions including changing the way data is organized.  Right now the public object might be a stand-alone float, tomorrow you might want to put it into a record, etc..  As long as you don&#8217;t rename the get and set, you can change your objects&#8217; names without affecting others.<br />
  That is the real value of encapsulation:  not &#8220;hiding&#8221; what you have or do from the eyes of other developers, just ensuring independence of development.  It&#8217;s not a rule, it&#8217;s a benefit to be weighed against its costs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-141946</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Wed, 17 Oct 2007 21:54:43 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-141946</guid>
		<description>I need to see a good explanation from someone, about why you would protect a data member, and have a public getter AS WELL AS a setter, instead of just making the member public.

I&#039;m a developer, and all of my schooling is in software.  However, everyone I work with (for the most part) are all EE majors, and are all 10 years older than I am.  I realized that I have no explanaition to give them, of why it is better to protect your data, even if public functions allow changes that would give the same effect as leaving the members public in the first place.

Aaron</description>
		<content:encoded><![CDATA[<p>I need to see a good explanation from someone, about why you would protect a data member, and have a public getter AS WELL AS a setter, instead of just making the member public.</p>
<p>I&#8217;m a developer, and all of my schooling is in software.  However, everyone I work with (for the most part) are all EE majors, and are all 10 years older than I am.  I realized that I have no explanaition to give them, of why it is better to protect your data, even if public functions allow changes that would give the same effect as leaving the members public in the first place.</p>
<p>Aaron</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-1506</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Fri, 02 Jun 2006 10:51:41 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-1506</guid>
		<description>The 24 hour clock example was addressed in the &lt;a href=&quot;http://cafe.elharo.com/java/eliminating-final/&quot; rel=&quot;nofollow&quot;&gt;previous post&lt;/a&gt;. In brief, you can add new methods that have different conditions; but under no circumstances is a subclass allowed to relax the postconditions of methods it overrides in the superclass. That&#039;s a violation of polymorphism. If you do that, the subclass is no longer a proper instance of the superclass. Code that depends on getting a value between 1 and 12 back from the &lt;code&gt;getHours()&lt;/code&gt; method will break when passed an instance of the subclass that returns values between 0 and 23. 

This is almost as bad as going back and changing the original class so that its &lt;code&gt;getHours()&lt;/code&gt; method returns a value between 0 and 23. You&#039;ve broken compatibility, and you could do this because the class was not closed. Do you need to do this sometimes? Sure, but subclassing has not gained you anything. Don&#039;t labor under the illusion that merely because you&#039;ve subclassed instead of changing the base class, you haven&#039;t broken anything. You absolutely have.

The solution is simple: add new methods to the subclass that do what you want. Do not overide and break the existing methods, conditions and invariants.</description>
		<content:encoded><![CDATA[<p>The 24 hour clock example was addressed in the <a href="http://cafe.elharo.com/java/eliminating-final/" rel="nofollow">previous post</a>. In brief, you can add new methods that have different conditions; but under no circumstances is a subclass allowed to relax the postconditions of methods it overrides in the superclass. That&#8217;s a violation of polymorphism. If you do that, the subclass is no longer a proper instance of the superclass. Code that depends on getting a value between 1 and 12 back from the <code>getHours()</code> method will break when passed an instance of the subclass that returns values between 0 and 23. </p>
<p>This is almost as bad as going back and changing the original class so that its <code>getHours()</code> method returns a value between 0 and 23. You&#8217;ve broken compatibility, and you could do this because the class was not closed. Do you need to do this sometimes? Sure, but subclassing has not gained you anything. Don&#8217;t labor under the illusion that merely because you&#8217;ve subclassed instead of changing the base class, you haven&#8217;t broken anything. You absolutely have.</p>
<p>The solution is simple: add new methods to the subclass that do what you want. Do not overide and break the existing methods, conditions and invariants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gp</title>
		<link>http://cafe.elharo.com/blogroll/the-three-reasons-for-data-encapsulation/comment-page-1/#comment-1307</link>
		<dc:creator>Gp</dc:creator>
		<pubDate>Thu, 01 Jun 2006 17:39:11 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/the-three-reasons-for-data-encapsulation/#comment-1307</guid>
		<description>I agree with making things private when they shouldn&#039;t be used by anyone else. But that doesn&#039;t mean you need to have less interfaces. The &quot;interface&quot; of the system should be well known so that the complexity of using the interface becomes a question for the documentation &quot;what interface do I use to accomplish X?&quot; Unless you have an entirely closed system (even to internal changes), this question will always come up.

&quot;Finally, we get to the first thing most textbooks cover. Separating implementation from interface allows the implementation to vary independently of the interface. For instance, you can switch a class from storing persistent data in a file to storing it in a database or vice versa. Sometimes this is important; but be honest: how many times have you really needed to do this? Out of the thousands of classes youâ€™ve written, how many have had significant changes in their internal data structures? Maybe 1 in 10? And in how many have you actually needed multiple simultaneous implementations? Maybe 1 in 100, or less?&quot;

Any platform that has a plugin interface will need this kind of flexibility. I deal with this daily. Each plugin has its own schema of data. The domain knowledge in the plugin is entirely separated from the system inerfaces. 

Now, I am not sure if you are arguing that all &quot;design by interface&quot; is bad or are you just saying that &quot;you need to be able to close the interface when you want to&quot;. 

I am firmly behind the latter point:
To your clock example. It looks like you have the class for an analog clock face. Down the road your Product Manager asks you to develop a digital clock face. Now there is a problem, digital clock faces usually have AM and PM indicators on North American clocks. Also imagine that you need to develop for Europe and need a digital clock that handles 24-hour time. How would you be able to do that while still maintaining the current class as it is implemented? You can&#039;t subclass and override your Final methods, so you would have to rewrite your clock class entirely to fit this change in. If you had built an IClock interface that has &quot;contracts&quot; for the constructor Clock (hrs, min) as well as virtual methods for setHours, setMinutes methods. Your &quot;final&quot; class would be &quot;AnalogClock12HR&quot;, and now you can build &quot;DigitalClock12HR&quot; as well as &quot;DigitalClock24HR&quot;. Now tell me how designing by interface does not let you perform data encapsulation. You can entirely close your class while letting the structure be flexible.</description>
		<content:encoded><![CDATA[<p>I agree with making things private when they shouldn&#8217;t be used by anyone else. But that doesn&#8217;t mean you need to have less interfaces. The &#8220;interface&#8221; of the system should be well known so that the complexity of using the interface becomes a question for the documentation &#8220;what interface do I use to accomplish X?&#8221; Unless you have an entirely closed system (even to internal changes), this question will always come up.</p>
<p>&#8220;Finally, we get to the first thing most textbooks cover. Separating implementation from interface allows the implementation to vary independently of the interface. For instance, you can switch a class from storing persistent data in a file to storing it in a database or vice versa. Sometimes this is important; but be honest: how many times have you really needed to do this? Out of the thousands of classes youâ€™ve written, how many have had significant changes in their internal data structures? Maybe 1 in 10? And in how many have you actually needed multiple simultaneous implementations? Maybe 1 in 100, or less?&#8221;</p>
<p>Any platform that has a plugin interface will need this kind of flexibility. I deal with this daily. Each plugin has its own schema of data. The domain knowledge in the plugin is entirely separated from the system inerfaces. </p>
<p>Now, I am not sure if you are arguing that all &#8220;design by interface&#8221; is bad or are you just saying that &#8220;you need to be able to close the interface when you want to&#8221;. </p>
<p>I am firmly behind the latter point:<br />
To your clock example. It looks like you have the class for an analog clock face. Down the road your Product Manager asks you to develop a digital clock face. Now there is a problem, digital clock faces usually have AM and PM indicators on North American clocks. Also imagine that you need to develop for Europe and need a digital clock that handles 24-hour time. How would you be able to do that while still maintaining the current class as it is implemented? You can&#8217;t subclass and override your Final methods, so you would have to rewrite your clock class entirely to fit this change in. If you had built an IClock interface that has &#8220;contracts&#8221; for the constructor Clock (hrs, min) as well as virtual methods for setHours, setMinutes methods. Your &#8220;final&#8221; class would be &#8220;AnalogClock12HR&#8221;, and now you can build &#8220;DigitalClock12HR&#8221; as well as &#8220;DigitalClock24HR&#8221;. Now tell me how designing by interface does not let you perform data encapsulation. You can entirely close your class while letting the structure be flexible.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

