<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;action=history&amp;feed=atom</id>
		<title>Encapsulate Behavior, not Just State - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;action=history"/>
		<updated>2013-05-23T09:52:13Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24711&amp;oldid=prev</id>
		<title>Kevlin at 17:38, 8 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24711&amp;oldid=prev"/>
				<updated>2009-07-08T17:38:13Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 17:38, 8 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory, containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood. Containment is supported by programming language constructs such as subroutines and functions, modules and packages, classes, and so on.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory, containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood. Containment is supported by programming language constructs such as subroutines and functions, modules and packages, classes, and so on.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Modules and packages address the larger scale needs for encapsulation, while classes, subroutines, and functions address the more fine-grained aspects of the matter. Over the years I have discovered that classes seem to be one of the hardest encapsulation constructs for developers to get right. It's not uncommon to find a class with a single 3000-line main method, or a class with only ''set'' and ''get'' methods for its primitive attributes. These examples demonstrate that the developers involved have not fully understood object-oriented thinking, having failed to take advantage of the power of objects as modeling constructs. For developers familiar with the terms POJO (&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Pure &lt;/del&gt;Old Java Object) and POCO (&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Pure &lt;/del&gt;Old C# Object), this was the intent going back to the basic of OO as a modelling paradigm.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Modules and packages address the larger scale needs for encapsulation, while classes, subroutines, and functions address the more fine-grained aspects of the matter. Over the years I have discovered that classes seem to be one of the hardest encapsulation constructs for developers to get right. It's not uncommon to find a class with a single 3000-line main method, or a class with only ''set'' and ''get'' methods for its primitive attributes. These examples demonstrate that the developers involved have not fully understood object-oriented thinking, having failed to take advantage of the power of objects as modeling constructs. For developers familiar with the terms POJO (&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Plain &lt;/ins&gt;Old Java Object) and POCO (&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Plain &lt;/ins&gt;Old C# &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Object or Plain Old CLR &lt;/ins&gt;Object), this was the intent going back to the basic of OO as a modelling paradigm &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; the objects are plain and simple, but not dumb&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. Consider a door object. It has four states: closed, open, closing, opening. It provides two operations: open and close. Depending on the state, the open and close operations will behave differently. This inherent property of an object makes the design process conceptually simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. Consider a door object. It has four states: closed, open, closing, opening. It provides two operations: open and close. Depending on the state, the open and close operations will behave differently. This inherent property of an object makes the design process conceptually simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24703&amp;oldid=prev</id>
		<title>Elandre at 09:34, 8 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24703&amp;oldid=prev"/>
				<updated>2009-07-08T09:34:56Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 09:34, 8 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory, containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood. Containment is supported by programming language constructs such as subroutines and functions, modules and packages, classes, and so on.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory, containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood. Containment is supported by programming language constructs such as subroutines and functions, modules and packages, classes, and so on.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Modules and packages address the larger scale needs for encapsulation, while classes, subroutines, and functions address the more fine-grained aspects of the matter. Over the years I have discovered that classes seem to be one of the hardest encapsulation constructs for developers to get right. It's not uncommon to find a class with a single 3000-line main method, or a class with only ''set'' and ''get'' methods for its primitive attributes. These examples demonstrate that the developers involved have not fully understood object-oriented thinking, having failed to take advantage of the power of objects as modeling constructs.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Modules and packages address the larger scale needs for encapsulation, while classes, subroutines, and functions address the more fine-grained aspects of the matter. Over the years I have discovered that classes seem to be one of the hardest encapsulation constructs for developers to get right. It's not uncommon to find a class with a single 3000-line main method, or a class with only ''set'' and ''get'' methods for its primitive attributes. These examples demonstrate that the developers involved have not fully understood object-oriented thinking, having failed to take advantage of the power of objects as modeling constructs&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. For developers familiar with the terms POJO (Pure Old Java Object) and POCO (Pure Old C# Object), this was the intent going back to the basic of OO as a modelling paradigm&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. Consider a door object. It has four states: closed, open, closing, opening. It provides two operations: open and close. Depending on the state, the open and close operations will behave differently. This inherent property of an object makes the design process conceptually simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. Consider a door object. It has four states: closed, open, closing, opening. It provides two operations: open and close. Depending on the state, the open and close operations will behave differently. This inherent property of an object makes the design process conceptually simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:24498:newid:24703 --&gt;
&lt;/table&gt;</summary>
		<author><name>Elandre</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24498&amp;oldid=prev</id>
		<title>Kevlin: Encapsulate behavior, not just state moved to Encapsulate Behavior, not Just State</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24498&amp;oldid=prev"/>
				<updated>2009-06-24T14:27:35Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;a href=&quot;/wiki/index.php/Encapsulate_behavior%2C_not_just_state&quot; title=&quot;Encapsulate behavior, not just state&quot;&gt;Encapsulate behavior, not just state&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/Encapsulate_Behavior%2C_not_Just_State&quot; title=&quot;Encapsulate Behavior, not Just State&quot;&gt;Encapsulate Behavior, not Just State&lt;/a&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 14:27, 24 June 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24497&amp;oldid=prev</id>
		<title>Kevlin at 14:26, 24 June 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=24497&amp;oldid=prev"/>
				<updated>2009-06-24T14:26:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 14:26, 24 June 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood. Containment is supported by programming language constructs such as subroutines and functions, modules and packages, classes, and so on.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood. Containment is supported by programming language constructs such as subroutines and functions, modules and packages, classes, and so on.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Modules and packages address the larger scale needs for encapsulation, while classes, subroutines and functions address the more fine-grained aspects of the matter. Over the years I have discovered that classes seem to be one of the hardest encapsulation constructs for developers to get right. It's not uncommon to find a class with a single 3000-line main method, or a class with only set and get methods for its primitive attributes. These examples &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;illustrates basically &lt;/del&gt;that the developers involved &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;never &lt;/del&gt;fully understood object-oriented thinking, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and &lt;/del&gt;the power of objects as modeling constructs.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Modules and packages address the larger scale needs for encapsulation, while classes, subroutines&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;and functions address the more fine-grained aspects of the matter. Over the years I have discovered that classes seem to be one of the hardest encapsulation constructs for developers to get right. It's not uncommon to find a class with a single 3000-line main method, or a class with only &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;set&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'' &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;get&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'' &lt;/ins&gt;methods for its primitive attributes. These examples &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;demonstrate &lt;/ins&gt;that the developers involved &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;have not &lt;/ins&gt;fully understood object-oriented thinking, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;having failed to take advantage of &lt;/ins&gt;the power of objects as modeling constructs.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Think of the object &lt;/del&gt;door&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, it &lt;/del&gt;has four states: closed, open, closing, opening. It &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;provide &lt;/del&gt;two operations: open and close. Depending on the state, the open and close operations will behave differently. This inherent property of an object makes the design process conceptually simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Consider a &lt;/ins&gt;door &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;object. It &lt;/ins&gt;has four states: closed, open, closing, opening. It &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;provides &lt;/ins&gt;two operations: open and close. Depending on the state, the open and close operations will behave differently. This inherent property of an object makes the design process conceptually simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How this works in practice is best illustrated with an example. Let's say we have three classes: &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Item&amp;lt;/code&amp;gt;. A &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt; object is the natural placeholder for the credit limit and credit validation rules. An &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt; object knows about its associated &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, and its &amp;lt;code&amp;gt;addItem&amp;lt;/code&amp;gt; operation delegates the actual credit check by calling &amp;lt;code&amp;gt;customer.validateCredit(item.price())&amp;lt;/code&amp;gt;. If the postcondition for the method fails, an exception can be thrown and the purchase aborted.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How this works in practice is best illustrated with an example. Let's say we have three classes: &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Item&amp;lt;/code&amp;gt;. A &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt; object is the natural placeholder for the credit limit and credit validation rules. An &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt; object knows about its associated &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, and its &amp;lt;code&amp;gt;addItem&amp;lt;/code&amp;gt; operation delegates the actual credit check by calling &amp;lt;code&amp;gt;customer.validateCredit(item.price())&amp;lt;/code&amp;gt;. If the postcondition for the method fails, an exception can be thrown and the purchase aborted.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Less experienced object oriented developers might decide to wrap all the business rules into an object very often referred to as &amp;lt;code&amp;gt;OrderManager&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;OrderService&amp;lt;/code&amp;gt;. In these designs, &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Item&amp;lt;/code&amp;gt; are treated as little more than record types. All logic is factored out of the classes and tied together in one large, procedural method with a lot of internal if-then-else constructs. These methods are easily broken and are almost impossible to maintain. The &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;main &lt;/del&gt;reason&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/del&gt;The encapsulation is broken.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Less experienced object oriented developers might decide to wrap all the business rules into an object very often referred to as &amp;lt;code&amp;gt;OrderManager&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;OrderService&amp;lt;/code&amp;gt;. In these designs, &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Item&amp;lt;/code&amp;gt; are treated as little more than record types. All logic is factored out of the classes and tied together in one large, procedural method with a lot of internal if-then-else constructs. These methods are easily broken and are almost impossible to maintain. The reason&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;? &lt;/ins&gt;The encapsulation is broken.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;So in the end, never break the encapsulation, and use the power of your programming language to maintain it.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;So in the end, never break the encapsulation, and use the power of your programming language to maintain it.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:12690:newid:24497 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12690&amp;oldid=prev</id>
		<title>Elandre: Never ever break the encapsulation moved to Encapsulate behavior, not just state: Captures the axioms intent better.</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12690&amp;oldid=prev"/>
				<updated>2008-10-16T19:12:23Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;a href=&quot;/wiki/index.php/Never_ever_break_the_encapsulation&quot; title=&quot;Never ever break the encapsulation&quot;&gt;Never ever break the encapsulation&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/Encapsulate_behavior%2C_not_just_state&quot; title=&quot;Encapsulate behavior, not just state&quot;&gt;Encapsulate behavior, not just state&lt;/a&gt;: Captures the axioms intent better.&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 19:12, 16 October 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</summary>
		<author><name>Elandre</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12680&amp;oldid=prev</id>
		<title>Kevlin at 21:59, 15 October 2008</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12680&amp;oldid=prev"/>
				<updated>2008-10-15T21:59:39Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:59, 15 October 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By Einar Landre&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;Einar Landre&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:12657:newid:12680 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12657&amp;oldid=prev</id>
		<title>Kevlin at 10:14, 15 October 2008</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12657&amp;oldid=prev"/>
				<updated>2008-10-15T10:14:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 10:14, 15 October 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, and its &lt;/del&gt;supported by programming language constructs such as &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;subroutine&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;function&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;module&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;package, object (class)&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In systems theory containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Containment is &lt;/ins&gt;supported by programming language constructs such as &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;subroutines and functions&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;modules and packages&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;classes&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and so on&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Module &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;package addresses &lt;/del&gt;the larger scale needs for encapsulation, while &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;object&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;subroutine &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;function addresses &lt;/del&gt;the more fine &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;granular &lt;/del&gt;aspects of the matter. Over the years I have discovered that &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;objects seams &lt;/del&gt;to be one of the hardest encapsulation constructs for developers to get right. It's not &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;seldom you &lt;/del&gt;find a class with &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;one &lt;/del&gt;single 3000 line main method, or a class with only set and get methods for its primitive attributes. These examples illustrates basically that the developers involved &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;has &lt;/del&gt;never understood object oriented thinking, and the power of objects as modeling constructs.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Modules &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;packages address &lt;/ins&gt;the larger scale needs for encapsulation, while &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;classes&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;subroutines &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;functions address &lt;/ins&gt;the more fine&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-grained &lt;/ins&gt;aspects of the matter. Over the years I have discovered that &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;classes seem &lt;/ins&gt;to be one of the hardest encapsulation constructs for developers to get right. It's not &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;uncommon to &lt;/ins&gt;find a class with &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/ins&gt;single 3000&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/ins&gt;line main method, or a class with only set and get methods for its primitive attributes. These examples illustrates basically that the developers involved never &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;fully &lt;/ins&gt;understood object&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/ins&gt;oriented thinking, and the power of objects as modeling constructs.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. Think of the object door, it has four states: closed, open, closing, opening. It provide two operations: open and close. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Dependent of &lt;/del&gt;state the open and close operations will behave differently. This inherent property of an object makes the design process &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;conceptual &lt;/del&gt;simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;An object encapsulates both state and behavior, where the behavior is defined by the actual state. Think of the object door, it has four states: closed, open, closing, opening. It provide two operations: open and close. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Depending on the &lt;/ins&gt;state&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;the open and close operations will behave differently. This inherent property of an object makes the design process &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;conceptually &lt;/ins&gt;simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How this works in practice is best illustrated &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;by &lt;/del&gt;an example. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Lets &lt;/del&gt;say we have three &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;objects&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;customer&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;order &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;item&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The customer &lt;/del&gt;object is the natural placeholder &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;of &lt;/del&gt;the credit limit and credit validation rules. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The order &lt;/del&gt;object knows about its associated &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;customer&lt;/del&gt;, and its addItem&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(item) &lt;/del&gt;operation delegates the actual credit check by calling customer.validateCredit(item.price()). If the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;post condition &lt;/del&gt;for the method fails, an exception &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;thrown and the purchase &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;aborted.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;How this works in practice is best illustrated &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;with &lt;/ins&gt;an example. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Let's &lt;/ins&gt;say we have three &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;classes: &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;&lt;/ins&gt;, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt;&lt;/ins&gt;, and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;Item&amp;lt;/code&amp;gt;&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;A &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt; &lt;/ins&gt;object is the natural placeholder &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;for &lt;/ins&gt;the credit limit and credit validation rules. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;An &amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt; &lt;/ins&gt;object knows about its associated &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;&lt;/ins&gt;, and its &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;&lt;/ins&gt;addItem&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/code&amp;gt; &lt;/ins&gt;operation delegates the actual credit check by calling &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;&lt;/ins&gt;customer.validateCredit(item.price())&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/code&amp;gt;&lt;/ins&gt;. If the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;postcondition &lt;/ins&gt;for the method fails, an exception &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;can be &lt;/ins&gt;thrown and the purchase aborted.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Less experienced object oriented developers might decide to wrap all the business rules into an object very often referred to as &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;order-manager &lt;/del&gt;or &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;order-service&lt;/del&gt;. In these designs &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;order&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;customer &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;item &lt;/del&gt;are treated as &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;records and all &lt;/del&gt;logic is factored out of the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;objects &lt;/del&gt;and tied together in one large method with a lot of internal if-then-else constructs. These methods are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;easilly flawed &lt;/del&gt;and almost impossible to maintain. The main reason: The encapsulation is broken.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Less experienced object oriented developers might decide to wrap all the business rules into an object very often referred to as &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;OrderManager&amp;lt;/code&amp;gt; &lt;/ins&gt;or &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;OrderService&amp;lt;/code&amp;gt;&lt;/ins&gt;. In these designs, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;Order&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Customer&amp;lt;/code&amp;gt;, &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;Item&amp;lt;/code&amp;gt; &lt;/ins&gt;are treated as &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;little more than record types. All &lt;/ins&gt;logic is factored out of the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;classes &lt;/ins&gt;and tied together in one large&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, procedural &lt;/ins&gt;method with a lot of internal if-then-else constructs. These methods are &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;easily broken &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/ins&gt;almost impossible to maintain. The main reason: The encapsulation is broken.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;So in the end, never break the encapsulation, and use the power of your &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;favorite object oriented &lt;/del&gt;language to maintain it.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;So in the end, never break the encapsulation, and use the power of your &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;programming &lt;/ins&gt;language to maintain it.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12440&amp;oldid=prev</id>
		<title>Elandre at 16:36, 1 October 2008</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12440&amp;oldid=prev"/>
				<updated>2008-10-01T16:36:51Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 16:36, 1 October 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 16:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 16:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;This work is licensed under a Creative Commons Attribution 3&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;This work is licensed under a Creative Commons Attribution 3&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Back to [[97 Things Every Programmer Should Know]] home page&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:12256:newid:12440 --&gt;
&lt;/table&gt;</summary>
		<author><name>Elandre</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12256&amp;oldid=prev</id>
		<title>Rmonson: New page: In systems theory containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation...</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Encapsulate_Behavior%2C_not_Just_State&amp;diff=12256&amp;oldid=prev"/>
				<updated>2008-08-21T12:53:09Z</updated>
		
		<summary type="html">&lt;p&gt;New page: In systems theory containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In systems theory containment is one of the most useful constructs when dealing with large and complex system structures. In the software industry the value of containment or encapsulation is well understood, and its supported by programming language constructs such as subroutine, function, module, package, object (class).&lt;br /&gt;
&lt;br /&gt;
Module and package addresses the larger scale needs for encapsulation, while object, subroutine and function addresses the more fine granular aspects of the matter. Over the years I have discovered that objects seams to be one of the hardest encapsulation constructs for developers to get right. It's not seldom you find a class with one single 3000 line main method, or a class with only set and get methods for its primitive attributes. These examples illustrates basically that the developers involved has never understood object oriented thinking, and the power of objects as modeling constructs.&lt;br /&gt;
&lt;br /&gt;
An object encapsulates both state and behavior, where the behavior is defined by the actual state. Think of the object door, it has four states: closed, open, closing, opening. It provide two operations: open and close. Dependent of state the open and close operations will behave differently. This inherent property of an object makes the design process conceptual simple. It boils down to two simple tasks: allocation and delegation of responsibility to the different objects including the inter-object interaction protocols.&lt;br /&gt;
&lt;br /&gt;
How this works in practice is best illustrated by an example. Lets say we have three objects, customer, order and item. The customer object is the natural placeholder of the credit limit and credit validation rules. The order object knows about its associated customer, and its addItem(item) operation delegates the actual credit check by calling customer.validateCredit(item.price()). If the post condition for the method fails, an exception is thrown and the purchase is aborted.&lt;br /&gt;
&lt;br /&gt;
Less experienced object oriented developers might decide to wrap all the business rules into an object very often referred to as order-manager or order-service. In these designs order, customer and item are treated as records and all logic is factored out of the objects and tied together in one large method with a lot of internal if-then-else constructs. These methods are easilly flawed and almost impossible to maintain. The main reason: The encapsulation is broken.&lt;br /&gt;
&lt;br /&gt;
So in the end, never break the encapsulation, and use the power of your favorite object oriented language to maintain it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By Einar Landre&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This work is licensed under a Creative Commons Attribution 3&lt;/div&gt;</summary>
		<author><name>Rmonson</name></author>	</entry>

	</feed>