<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-11933937.post4982606554165380166..comments</id><updated>2008-06-27T21:17:17.662-05:00</updated><category term='pattern'/><category term='.net'/><category term='agile'/><category term='mysql'/><category term='ruby/rails'/><category term='humor'/><category term='efficiency'/><title type='text'>Comments on STEPHEN CHU . com: Learning encapsulation should come before learning...</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.stephenchu.com/feeds/4982606554165380166/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html'/><author><name>Stephen Chu</name><uri>http://www.blogger.com/profile/07181510921622947661</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-11933937.post-6637467467097318629</id><published>2008-06-27T21:17:00.000-05:00</published><updated>2008-06-27T21:17:00.000-05:00</updated><title type='text'>One sign that you're breaking encapsulation is whe...</title><content type='html'>One sign that you're breaking encapsulation is when you violate the guideline of demeter.  It may not be easy to spot in your milk example, but when you rewrite it like:&lt;BR/&gt;&lt;BR/&gt;@milk.expiration_date.&lt;(2.days.from_now)&lt;BR/&gt;&lt;BR/&gt;it becomes obvious.&lt;BR/&gt;&lt;BR/&gt;So while demeter is just a guideline, understanding that guideline gives you immediate insight into situations where your code is coupled to some particular object structure.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/6637467467097318629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/6637467467097318629'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1214619420000#c6637467467097318629' title=''/><author><name>Pat Maddox</name><uri>http://evang.eli.st/blog</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-165087705'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-6406259075193475191</id><published>2008-06-23T02:56:00.000-05:00</published><updated>2008-06-23T02:56:00.000-05:00</updated><title type='text'>...which I suppose is really another argument in f...</title><content type='html'>...which I suppose is really another argument in favor of encapsulation. It's easy to make a mistake in a quick one-liner, but the encapsulated version will probably be more thorough.&lt;BR/&gt;Or at least if it's not, then after a few people get sick you can fix all the code in one place.  :-)&lt;BR/&gt;&lt;BR/&gt;P.S. Date and Time arithmetic drive me nuts. I've been programming for more years than I can count (heh) and I still have to carefully think it through every time.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/6406259075193475191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/6406259075193475191'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1214207760000#c6406259075193475191' title=''/><author><name>Fred Swatz</name><uri>http://www.blogger.com/profile/04372593126664129228</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-493787143'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-8603015562635066565</id><published>2008-06-23T02:47:00.000-05:00</published><updated>2008-06-23T02:47:00.000-05:00</updated><title type='text'>Well, presumably it's intended to mean "if the mil...</title><content type='html'>Well, presumably it's intended to mean "if the milk is going to expire in two days or less, drink it." But what it actually says is "If the expiration date is earlier than the day after tomorrow, drink it." So it could have expired a year ago, and you'll drink it and die.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/8603015562635066565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/8603015562635066565'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1214207220000#c8603015562635066565' title=''/><author><name>Fred Swatz</name><uri>http://www.blogger.com/profile/04372593126664129228</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-493787143'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-511360723154523667</id><published>2008-06-22T23:12:00.000-05:00</published><updated>2008-06-22T23:12:00.000-05:00</updated><title type='text'>@fred:&lt;br&gt;&lt;br&gt;I'm not sure what you mean. Could yo...</title><content type='html'>@fred:&lt;BR/&gt;&lt;BR/&gt;I'm not sure what you mean. Could you elaborate?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/511360723154523667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/511360723154523667'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1214194320000#c511360723154523667' title=''/><author><name>Stephen Chu</name><uri>http://www.blogger.com/profile/07181510921622947661</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-3841993'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-1707993491112690582</id><published>2008-06-22T16:04:00.000-05:00</published><updated>2008-06-22T16:04:00.000-05:00</updated><title type='text'>This is beside the point, but I don't think the ex...</title><content type='html'>This is beside the point, but I don't think the example does what one might think it does.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/1707993491112690582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/1707993491112690582'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1214168640000#c1707993491112690582' title=''/><author><name>Fred Swatz</name><uri>http://www.blogger.com/profile/04372593126664129228</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-493787143'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-8377087149444713387</id><published>2008-06-18T12:13:00.000-05:00</published><updated>2008-06-18T12:13:00.000-05:00</updated><title type='text'>@brian:&lt;br&gt;&lt;br&gt;I agree with you when you say "in c...</title><content type='html'>@brian:&lt;BR/&gt;&lt;BR/&gt;I agree with you when you say "in certain cases information in a class may be used in ways that don't concern it." But I am not convinced by the example that you gave.&lt;BR/&gt;&lt;BR/&gt;If my &lt;I&gt;@milk&lt;/I&gt; object can answer &lt;I&gt;expiring?&lt;/I&gt; and &lt;I&gt;expired?&lt;/I&gt;, then you will still maintain the differentiation. If you have cases where you truly don't care, you can have another method &lt;I&gt;discount_item?&lt;/I&gt;, which will become a new business concept.&lt;BR/&gt;&lt;BR/&gt;One of the advantages of properly encapsulating states is that I can change the implementation of my &lt;I&gt;Milk&lt;/I&gt; class without code changes of calling code. I can re-implement &lt;I&gt;expiring?&lt;/I&gt; using the code like my blog entry hard-coded, or a string column, or talking to an inventory catalog web service, anything.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/8377087149444713387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/8377087149444713387'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1213809180000#c8377087149444713387' title=''/><author><name>Stephen Chu</name><uri>http://www.blogger.com/profile/07181510921622947661</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-3841993'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-7672288647180432650</id><published>2008-06-18T11:37:00.000-05:00</published><updated>2008-06-18T11:37:00.000-05:00</updated><title type='text'>Thank you. Your post has finally codified in my he...</title><content type='html'>Thank you. Your post has finally codified in my head why I've always had a problem with "tell, don't ask." In your milk example, you have now enforced a standard that I may or may not want in that "milk" now tells me if it is expired and I no longer know if this means it's 2 days before expiration which might mean I need to go get some milk or if it's past the expiration date and I shouldn't drink it.&lt;BR/&gt;&lt;BR/&gt;I understand the point of "tell, don't ask" is for better separation of concerns, but in certain cases information in a class may be used in ways that don't concern it.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/7672288647180432650'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/7672288647180432650'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1213807020000#c7672288647180432650' title=''/><author><name>Brian Yamabe</name><uri>http://www.blogger.com/profile/04535848221157850349</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1199677334'/></entry><entry><id>tag:blogger.com,1999:blog-11933937.post-9129566451157128639</id><published>2008-06-18T09:30:00.000-05:00</published><updated>2008-06-18T09:30:00.000-05:00</updated><title type='text'>Preach it, Chu.</title><content type='html'>Preach it, Chu.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/9129566451157128639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11933937/4982606554165380166/comments/default/9129566451157128639'/><link rel='alternate' type='text/html' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html?showComment=1213799400000#c9129566451157128639' title=''/><author><name>Clint Bishop</name><uri>http://www.blogger.com/profile/01603091339856637791</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.stephenchu.com/2008/06/learning-encapsulation-should-come.html' ref='tag:blogger.com,1999:blog-11933937.post-4982606554165380166' source='http://www.blogger.com/feeds/11933937/posts/default/4982606554165380166' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2129322687'/></entry></feed>
