<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tag 'OOP'</title><link>http://msmvps.com/search/SearchResults.aspx?q=app:weblogs&amp;tag=OOP&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tag 'OOP'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Understanding Object Binding</title><link>http://msmvps.com/blogs/deborahk/archive/2009/09/08/understanding-object-binding.aspx</link><pubDate>Tue, 08 Sep 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1721653</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;Before going through the details of how to use object binding, it is important to understand exactly what it is—and what it is not. Object binding is binding your business object properties to user interface elements. Object binding is not database binding in the strict sense of the term. It does not directly collect or bind any data from your database.&lt;/p&gt;  &lt;p&gt;When you are using business object classes &lt;em&gt;without&lt;/em&gt; object binding, the flow of data from the database to your user interface and back again requires these steps:&lt;/p&gt;  &lt;p&gt;1. The &lt;strong&gt;business object calls the data access component&lt;/strong&gt; to get the data from the database and sets the business object properties using that data.&lt;/p&gt;  &lt;p&gt;For example, the Product class calls the data access component, which uses a query or stored procedure to fill a DataTable from the Product table. The data access component returns the DataTable to the Product class, which assigns each field from the table to a property of the object. To illustrate, the line of code required to get the ProductName field from the DataTable and set the   &lt;br /&gt;ProductName property is as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = dt.Rows[0][&amp;quot;ProductName&amp;quot;];&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = dt.Rows(0).Item(&amp;quot;ProductName&amp;quot;)&lt;/font&gt;    &lt;br /&gt;    &lt;br /&gt;2. The &lt;strong&gt;user interface component accesses the business object&lt;/strong&gt; properties to fill the values of the controls on the form.&lt;/p&gt;  &lt;p&gt;For example, each control on the ProductWin form is assigned to the value of the appropriate Product business object property. To illustrate, the line of code required to set the Text property of the Name TextBox control to the ProductName property of the Product business object is as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;NameTextBox.Text = myProduct.ProductName&lt;/font&gt;;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;NameTextBox.Text = myProduct.ProductName&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;3. After the user makes any changes, the user interface component assigns the current &lt;strong&gt;values in the controls back to the business object&lt;/strong&gt; properties.&lt;/p&gt;  &lt;p&gt;For example, the value in each control on the ProductWin form is assigned back to its associated Product business object property. To illustrate, the line of code required to set the ProductName property to the current value in the Name TextBox control is as follows:&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = NameTextBox.Text&lt;/font&gt;;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = NameTextBox.Text&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;4. The &lt;strong&gt;business object component updates the DataTable&lt;/strong&gt; using the property values and passes it back to the data access component, which updates the database with the changed data. &lt;/p&gt;  &lt;p&gt;For example, the value of each Product business object property is assigned to the associated field in the DataTable, and the result is passed to the data access component, which updates the Product table. To illustrate, the line of code required to set the ProductName field in the DataTable to the value of the ProductName business object property is as follows:&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;dt.Rows[0][&amp;quot;ProductName&amp;quot;] = myProduct.ProductName;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;dt.Rows(0).item(&amp;quot;ProductName&amp;quot;) = myProduct.ProductName&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Using object binding allows you to skip steps 2 and 3. Object binding automatically populates the controls on the user interface from the business object properties. As the users change the contents of the controls, object binding updates the associated business object properties, keeping them in synchronization.&lt;/p&gt;  &lt;p&gt;That still leaves steps 1 and 4 for you. This &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/07/dal-data-access-layer.aspx" target="_blank"&gt;link&lt;/a&gt; provides information on building a data access component to handle steps 1 and 4.&lt;/p&gt;  &lt;p&gt;In summary, object binding is the process of binding control properties directly to properties of your business objects. For example, you could bind the Text property of a TextBox control to the ProductName property of a Product business object. When the form is displayed, the runtime automatically displays the value of the ProductName property in the TextBox. And if the user changes the text in the TextBox control, the runtime modifies the ProductName property accordingly. This saves you from writing the code required to transfer data back and forth between the controls on the user interface and the business object properties.&lt;/p&gt;  &lt;p&gt;Visual Studio provides design-time tools for working with your business objects as data sources for your user interface, making it easy to bind each control to its associated business object property. The only requirement for your business objects to work with these tools is that the business object class needs at least one public property. No specific constructors, interfaces, or attributes are needed.&lt;/p&gt;  &lt;h2&gt;Object Binding Versus Data Binding&lt;/h2&gt;  &lt;p&gt;Don’t confuse the term object binding with the more generalized term data binding. Data binding is the broad term for binding control properties to data from any data source. Object binding is just one type of data binding. Some common types of data binding are as follows:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Binding to tables in a database (Visual Studio generates code to     &lt;br /&gt;define a typed DataSet and TableAdapters)&lt;/li&gt;    &lt;li&gt;Binding to stored procedures in a database (Visual Studio generates     &lt;br /&gt;code to define a typed DataSet and TableAdapters)&lt;/li&gt;    &lt;li&gt;Binding to a business object (object binding does not generate code;     &lt;br /&gt;it just sets control properties)&lt;/li&gt;    &lt;li&gt;Binding to an array or collection of data&lt;/li&gt;    &lt;li&gt;Binding to a Web service&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;When binding to a database, Visual Studio generates a significant amount of code and then binds the user interface to that generated code. Object binding binds to &lt;strong&gt;your&lt;/strong&gt; code. That gives you much more control and greatly simplifies the maintenance of your application.    &lt;br /&gt;&lt;/p&gt;  &lt;h2&gt;Using Object Binding&lt;/h2&gt;  &lt;p&gt;You use object binding by following these steps:&lt;/p&gt;  &lt;p&gt;1. Build the business objects for your application.&lt;/p&gt;  &lt;p&gt;2. Define a business object data source in the Windows Application   &lt;br /&gt;project containing your user interface.&lt;/p&gt;  &lt;p&gt;3. Bind properties of the controls on the form to business object   &lt;br /&gt;properties.&lt;/p&gt;  &lt;p&gt;Although it is much easier to think about object binding as a direct binding of a control’s property to a specific business object’s property, object binding frequently uses a BindingSource component as an intermediary. A &lt;strong&gt;BindingSource&lt;/strong&gt; is a component on a form that binds the controls on the form to the business object. Each control is bound to the BindingSource component, which in turn is bound to the business object. This makes it much easier to change the binding for all controls by changing the BindingSource without having to separately rebind each control.&lt;/p&gt;  &lt;p&gt;You set the BindingSource to an individual business object instance in your code. The runtime then binds all the properties associated with that instance to the controls, thereby displaying the business object property values in the controls. And as the user changes the content of any controls, the business object property values are changed accordingly.&lt;/p&gt;  &lt;p&gt;A form can contain multiple BindingSource components. For example, a ProductWin form can contain product data and display a drop-down list of product types. You can define a BindingSource component for the product data and a second BindingSource component for the product type data.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>Understanding Object Binding</title><link>http://msmvps.com/blogs/deborahk/archive/2009/09/08/understanding-object-binding.aspx</link><pubDate>Tue, 08 Sep 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1721653</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;Before going through the details of how to use object binding, it is important to understand exactly what it is—and what it is not. Object binding is binding your business object properties to user interface elements. Object binding is not database binding in the strict sense of the term. It does not directly collect or bind any data from your database.&lt;/p&gt;  &lt;p&gt;When you are using business object classes &lt;em&gt;without&lt;/em&gt; object binding, the flow of data from the database to your user interface and back again requires these steps:&lt;/p&gt;  &lt;p&gt;1. The &lt;strong&gt;business object calls the data access component&lt;/strong&gt; to get the data from the database and sets the business object properties using that data.&lt;/p&gt;  &lt;p&gt;For example, the Product class calls the data access component, which uses a query or stored procedure to fill a DataTable from the Product table. The data access component returns the DataTable to the Product class, which assigns each field from the table to a property of the object. To illustrate, the line of code required to get the ProductName field from the DataTable and set the    &lt;br /&gt;ProductName property is as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = dt.Rows[0][&amp;quot;ProductName&amp;quot;];&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = dt.Rows(0).Item(&amp;quot;ProductName&amp;quot;)&lt;/font&gt;     &lt;br /&gt;    &lt;br /&gt;2. The &lt;strong&gt;user interface component accesses the business object&lt;/strong&gt; properties to fill the values of the controls on the form.&lt;/p&gt;  &lt;p&gt;For example, each control on the ProductWin form is assigned to the value of the appropriate Product business object property. To illustrate, the line of code required to set the Text property of the Name TextBox control to the ProductName property of the Product business object is as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;NameTextBox.Text = myProduct.ProductName&lt;/font&gt;;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;NameTextBox.Text = myProduct.ProductName&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;3. After the user makes any changes, the user interface component assigns the current &lt;strong&gt;values in the controls back to the business object&lt;/strong&gt; properties.&lt;/p&gt;  &lt;p&gt;For example, the value in each control on the ProductWin form is assigned back to its associated Product business object property. To illustrate, the line of code required to set the ProductName property to the current value in the Name TextBox control is as follows:&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = NameTextBox.Text&lt;/font&gt;;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;myProduct.ProductName = NameTextBox.Text&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;4. The &lt;strong&gt;business object component updates the DataTable&lt;/strong&gt; using the property values and passes it back to the data access component, which updates the database with the changed data. &lt;/p&gt;  &lt;p&gt;For example, the value of each Product business object property is assigned to the associated field in the DataTable, and the result is passed to the data access component, which updates the Product table. To illustrate, the line of code required to set the ProductName field in the DataTable to the value of the ProductName business object property is as follows:&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;dt.Rows[0][&amp;quot;ProductName&amp;quot;] = myProduct.ProductName;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;dt.Rows(0).item(&amp;quot;ProductName&amp;quot;) = myProduct.ProductName&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Using object binding allows you to skip steps 2 and 3. Object binding automatically populates the controls on the user interface from the business object properties. As the users change the contents of the controls, object binding updates the associated business object properties, keeping them in synchronization.&lt;/p&gt;  &lt;p&gt;That still leaves steps 1 and 4 for you. This &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/07/dal-data-access-layer.aspx" target="_blank"&gt;link&lt;/a&gt; provides information on building a data access component to handle steps 1 and 4.&lt;/p&gt;  &lt;p&gt;In summary, object binding is the process of binding control properties directly to properties of your business objects. For example, you could bind the Text property of a TextBox control to the ProductName property of a Product business object. When the form is displayed, the runtime automatically displays the value of the ProductName property in the TextBox. And if the user changes the text in the TextBox control, the runtime modifies the ProductName property accordingly. This saves you from writing the code required to transfer data back and forth between the controls on the user interface and the business object properties.&lt;/p&gt;  &lt;p&gt;Visual Studio provides design-time tools for working with your business objects as data sources for your user interface, making it easy to bind each control to its associated business object property. The only requirement for your business objects to work with these tools is that the business object class needs at least one public property. No specific constructors, interfaces, or attributes are needed.&lt;/p&gt;  &lt;h2&gt;Object Binding Versus Data Binding&lt;/h2&gt;  &lt;p&gt;Don’t confuse the term object binding with the more generalized term data binding. Data binding is the broad term for binding control properties to data from any data source. Object binding is just one type of data binding. Some common types of data binding are as follows:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Binding to tables in a database (Visual Studio generates code to      &lt;br /&gt;define a typed DataSet and TableAdapters) &lt;/li&gt;    &lt;li&gt;Binding to stored procedures in a database (Visual Studio generates      &lt;br /&gt;code to define a typed DataSet and TableAdapters) &lt;/li&gt;    &lt;li&gt;Binding to a business object (object binding does not generate code;      &lt;br /&gt;it just sets control properties) &lt;/li&gt;    &lt;li&gt;Binding to an array or collection of data &lt;/li&gt;    &lt;li&gt;Binding to a Web service &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;When binding to a database, Visual Studio generates a significant amount of code and then binds the user interface to that generated code. Object binding binds to &lt;strong&gt;your&lt;/strong&gt; code. That gives you much more control and greatly simplifies the maintenance of your application.     &lt;br /&gt;&lt;/p&gt;  &lt;h2&gt;Using Object Binding&lt;/h2&gt;  &lt;p&gt;You use object binding by following these steps:&lt;/p&gt;  &lt;p&gt;1. Build the business objects for your application.&lt;/p&gt;  &lt;p&gt;2. Define a business object data source in the Windows Application    &lt;br /&gt;project containing your user interface.&lt;/p&gt;  &lt;p&gt;3. Bind properties of the controls on the form to business object    &lt;br /&gt;properties.&lt;/p&gt;  &lt;p&gt;Although it is much easier to think about object binding as a direct binding of a control’s property to a specific business object’s property, object binding frequently uses a BindingSource component as an intermediary. A &lt;strong&gt;BindingSource&lt;/strong&gt; is a component on a form that binds the controls on the form to the business object. Each control is bound to the BindingSource component, which in turn is bound to the business object. This makes it much easier to change the binding for all controls by changing the BindingSource without having to separately rebind each control.&lt;/p&gt;  &lt;p&gt;You set the BindingSource to an individual business object instance in your code. The runtime then binds all the properties associated with that instance to the controls, thereby displaying the business object property values in the controls. And as the user changes the content of any controls, the business object property values are changed accordingly.&lt;/p&gt;  &lt;p&gt;A form can contain multiple BindingSource components. For example, a ProductWin form can contain product data and display a drop-down list of product types. You can define a BindingSource component for the product data and a second BindingSource component for the product type data.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;For more information on object binding, see these links:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/08/using-object-binding.aspx" target="_blank"&gt;Using Object Binding&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/16/binding-control-properties-to-business-object-properties.aspx"&gt;Binding Control Properties to Business Object Properties&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>Basic Pillars of an Object-Oriented System</title><link>http://msmvps.com/blogs/deborahk/archive/2009/09/01/basic-pillars-of-an-object-oriented-system.aspx</link><pubDate>Tue, 01 Sep 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1719927</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;The four basic elements of an object-oriented system are &lt;strong&gt;abstraction&lt;/strong&gt;,     &lt;br /&gt;&lt;strong&gt;encapsulation&lt;/strong&gt;, &lt;strong&gt;inheritance&lt;/strong&gt;, and &lt;strong&gt;polymorphism&lt;/strong&gt;. This post defines     &lt;br /&gt;these terms and describes why they are important to software design and     &lt;br /&gt;development.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of OO, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-oo.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;h2&gt;Abstraction: Focusing on What is Important&lt;/h2&gt;  &lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt; is a technique that we all use to manage the complexity of the     &lt;br /&gt;information we collect every day. It allows us to recognize how things are     &lt;br /&gt;similar and ignore how they are different, to think about generalities and     &lt;br /&gt;not specifics, and to see what things are without thinking about what makes     &lt;br /&gt;them that way. You can abstract important characteristics at any given time     &lt;br /&gt;and for any particular purpose and ignore all other aspects.&lt;/p&gt;  &lt;p&gt;How you develop an abstraction depends on both its purpose and your    &lt;br /&gt;perspective. For example, on a warm summer day I look at a tree and     &lt;br /&gt;abstract it as a shade provider. A young child abstracts it as a place to     &lt;br /&gt;climb. One tree, two different abstractions.&lt;/p&gt;  &lt;p&gt;Abstraction is used to identify the objects involved with a particular    &lt;br /&gt;application. In developing a payroll system, you would think about Jessica     &lt;br /&gt;Jones and abstract her as an employee, thinking only about her salary and     &lt;br /&gt;how she gets paid. When working on the company softball league application, you would abstract Jessica as a player and be more concerned with her position and batting average. One object, two completely different abstractions.&lt;/p&gt;  &lt;p&gt;Scenarios (or use cases) can ensure that the correct abstraction is used in a particular application. They provide context for the objects, giving them a purpose. &lt;/p&gt;  &lt;p&gt;Using abstraction, you can focus on the objects and not on the implementation. This lets you think about what needs to be done and not how the computer will do it.&lt;/p&gt;  &lt;h2&gt;Encapsulation: Hiding Your Private Parts&lt;/h2&gt;  &lt;p&gt;Most organizations have independent units, usually called departments.    &lt;br /&gt;The sales department makes the sales, the production department produces     &lt;br /&gt;the item, the shipping department ships it, and so on. Each department     &lt;br /&gt;is responsible for its own procedures and internal information. For example, the sales department has procedures for calling prospects, evaluating     &lt;br /&gt;the opportunity, sending sales materials, following up with current     &lt;br /&gt;customers, maintaining prospect information, and so on.&lt;/p&gt;  &lt;p&gt;You could say the departments are &lt;strong&gt;encapsulated&lt;/strong&gt; because the internal     &lt;br /&gt;information (properties) and standard operating procedures (methods)     &lt;br /&gt;are contained within the department. These are figuratively hidden from     &lt;br /&gt;other departments except through defined interfaces. Anyone who needs     &lt;br /&gt;the department’s procedures or information goes to that department to     &lt;br /&gt;ask for it.&lt;/p&gt;  &lt;p&gt;If a shipping clerk acquires the name of a prospect, the clerk knows    &lt;br /&gt;better than to handle the prospect directly. Instead, the clerk collaborates     &lt;br /&gt;with the sales department by using the publicly accessible defining prospects     &lt;br /&gt;feature and sends the name to them.&lt;/p&gt;  &lt;p&gt;The same principles are used in object-oriented applications to encapsulate    &lt;br /&gt;each object’s properties and methods. When an object needs to perform     &lt;br /&gt;a procedure that is encapsulated in another class, it does not perform     &lt;br /&gt;the procedure directly. Instead, it collaborates with an object belonging to     &lt;br /&gt;the other class to perform the procedure.&lt;/p&gt;  &lt;p&gt;Encapsulation aids in abstraction by hiding the internal implementation    &lt;br /&gt;of an object within the class. You then can use an object without     &lt;br /&gt;understanding how its class is implemented. So the shipping clerk can     &lt;br /&gt;define a prospect to the sales department without knowing how the sales     &lt;br /&gt;department actually handles the prospect.&lt;/p&gt;  &lt;h2&gt;Inheritance: Attaining Reuse&lt;/h2&gt;  &lt;p&gt;Things that are similar still have some differences, and things that are    &lt;br /&gt;different often have some similarities. Reviewing the inheritance     &lt;br /&gt;example (from my post &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-inheritance.aspx" target="_blank"&gt;here&lt;/a&gt;), both your desk phone and your cell phone can be classified as phones. Looking at their differences, your desk phone can transfer calls, and your cell phone can take pictures.&lt;/p&gt;  &lt;p&gt;Say you are asked to create phone emulator software. You could implement    &lt;br /&gt;all properties and methods for a cell phone into a cell phone class. This class would include volume and picture count properties and dial, answer, disconnect, and take picture methods. Likewise, you could implement all properties and methods for a desk phone into a desk phone class.&lt;/p&gt;  &lt;p&gt;This class would include volume and line status properties and dial,    &lt;br /&gt;answer, disconnect, and transfer call methods. This duplicates the common     &lt;br /&gt;phone information and functionality in both classes.&lt;/p&gt;  &lt;p&gt;You can remove the property and method redundancy and attain reuse    &lt;br /&gt;by using &lt;strong&gt;inheritance&lt;/strong&gt;. You can remove the common phone properties and     &lt;br /&gt;methods from the specialized classes and put them in a higher-level phone     &lt;br /&gt;class. The cell phone class and desk phone class can then inherit from the     &lt;br /&gt;phone class, attaining all its properties and methods. This “is a” relationship     &lt;br /&gt;is depicted &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-inheritance.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If a new type of phone class, such as a Web phone, were added, objects of the new class would automatically have all the properties and methods defined for the base phone class, greatly simplifying the development of the new class.    &lt;br /&gt;Inheritance is a powerful tool for code reuse.&lt;/p&gt;  &lt;h2&gt;Polymorphism: Same Behavior, Different Implementation&lt;/h2&gt;  &lt;p&gt;Two or more classes can have methods that are named the same and have    &lt;br /&gt;the same basic purpose but different implementations. This is &lt;strong&gt;polymorphism&lt;/strong&gt;.     &lt;br /&gt;The Text property of the .NET Framework is an example of polymorphism.     &lt;br /&gt;Although the basic purpose of the Text property is the same, how the property works depends on whether you are setting the Text property of a Form, a Label, or a TextBox.&lt;/p&gt;  &lt;p&gt;In the phone example, say the implementation of the Dial method    &lt;br /&gt;needed to be different in the cell phone class and the desk phone class.     &lt;br /&gt;The cell phone class would then need its own Dial method, and a desk     &lt;br /&gt;phone class would need its own Dial method. You can request the Dial     &lt;br /&gt;method by an object from either class without knowing how either class     &lt;br /&gt;plans to implement that request. Both the cell phone class and the desk     &lt;br /&gt;phone class have the Dial method, but the implementation of that behavior     &lt;br /&gt;can be completely different.&lt;/p&gt;  &lt;p&gt;Polymorphism can be implemented using inheritance. The base phone    &lt;br /&gt;class would retain a Dial method, but the implementation would be empty     &lt;br /&gt;(or would provide a default implementation). Each derived class would     &lt;br /&gt;then override the base class Dial method by implementing the method.     &lt;br /&gt;The result is that the desk phone class and cell phone class each have a     &lt;br /&gt;Dial method, but the implementations are different.&lt;/p&gt;  &lt;p&gt;Polymorphism can also be implemented using an interface. In the    &lt;br /&gt;phone example, the Dial method would be removed from the base phone     &lt;br /&gt;class. An IDial interface would define the properties and methods for     &lt;br /&gt;handling dialing. Both the desk phone class and cell phone class implement     &lt;br /&gt;this interface so that they both have the same properties and methods     &lt;br /&gt;for dialing but different implementations. (See &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-an-interface.aspx" target="_blank"&gt;this link&lt;/a&gt; for more information on interfaces.)&lt;/p&gt;  &lt;p&gt;The benefit of polymorphism is that you don’t need to know the    &lt;br /&gt;object’s class to execute the polymorphic behavior. For example, you may     &lt;br /&gt;have many classes in an application, each with its own save method. When     &lt;br /&gt;the application is saved, each object knows the class it belongs to and automatically calls the correct save routine.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>What is an Interface?</title><link>http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-an-interface.aspx</link><pubDate>Tue, 01 Sep 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1719921</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;When talking about OO, the term “interface” has nothing to do with your   &lt;br /&gt;user interface. An &lt;strong&gt;interface&lt;/strong&gt; defines a list of properties and methods that    &lt;br /&gt;a class can implement. But if the class implements a particular interface, it    &lt;br /&gt;must implement all properties and methods defined by that interface.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of OO, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-oo.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;For example, you can think of a phone as implementing a dial interface,   &lt;br /&gt;IDial. (By convention, interfaces begin with the letter I.) This interface defines Connect and MakeTone methods but does not implement them. This allows each phone to define how it connects and makes tones. Every phone that implements the IDial interface must provide an implementation    &lt;br /&gt;for both the connect and make tone methods.&lt;/p&gt;  &lt;p&gt;An interface is different from a base class in that an interface defines   &lt;br /&gt;the list of properties and methods with no implementation. The implementation    &lt;br /&gt;is left to the class that implements the interface. A base class contains both the list of properties and methods and their implementation. The class that inherits from the base class does not need to provide any implementation.&lt;/p&gt;  &lt;p&gt;In your application, you can implement interfaces provided in the   &lt;br /&gt;.NET Framework or define and implement your own interfaces. For    &lt;br /&gt;example, if you want to ensure that every MDI child form in your application    &lt;br /&gt;provides a standard set of methods, you could define an IMDIChild interface as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public interface IMDIChild     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; bool ProcessDelete();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; bool ProcessNew();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; bool ProcessSave();      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Interface IMDIChild     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Function ProcessDelete() As Boolean      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Function ProcessNew() As Boolean      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Function ProcessSave() As Boolean      &lt;br /&gt;End Interface&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In this example, the interface is comprised of three methods: ProcessDelete, ProcessNew, and ProcessSave. Each of these methods must be implemented in any class that implements this interface.&lt;/p&gt;  &lt;p&gt;To implement an interface in a class, specify the interface when defining the class. For example, if the TimeSheetWin class implements the IMDIChild   &lt;br /&gt;interface, it would look like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public class TimeSheetWin : IMDIChild&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Class TimeSheetWin     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Implements IMDIChild&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Each class that implements this interface must provide an implementation   &lt;br /&gt;for all three of the interface methods. &lt;/p&gt;  &lt;p&gt;[For an example of implementing the .NET IDataErrorInfo and INotifyPropertyChanged interfaces, see &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx" target="_blank"&gt;this link&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;Implementing an interface allows a class to be more formal about the   &lt;br /&gt;behavior it promises to provide. Interfaces form a contract between the    &lt;br /&gt;class and the rest of the application, and the compiler enforces this contract.    &lt;br /&gt;If your class claims to implement an interface, all methods defined by that    &lt;br /&gt;interface must be implemented before the class successfully compiles.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>What is Inheritance?</title><link>http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-inheritance.aspx</link><pubDate>Tue, 01 Sep 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1719911</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;In object-oriented (OO) terms, inheritance defines an “is a” relationship between two or more classes. A beagle &lt;em&gt;is a&lt;/em&gt; dog, and a poodle &lt;em&gt;is a&lt;/em&gt; dog, so both beagle and poodle inherit from dog. Both beagle and poodle have dog attributes and exhibit dog behaviors. A dog class in this example is called the &lt;strong&gt;parent class&lt;/strong&gt; or &lt;strong&gt;base class&lt;/strong&gt;, and the classes that inherit from it (beagle and poodle) are called &lt;strong&gt;child classes&lt;/strong&gt; or &lt;strong&gt;derived classes&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of OO, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-oo.aspx" target="_blank"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;Likewise, think about your phone. All types of phones have basic    &lt;br /&gt;phone attributes and behaviors, such as volume, dial, answer, and disconnect.     &lt;br /&gt;Your desk phone may have additional, specialized behaviors, such     &lt;br /&gt;as transfer features. Your cell phone has amazing features such as taking     &lt;br /&gt;pictures and playing movies. &lt;/p&gt;  &lt;p&gt;Even though each type of phone may have specialized behaviors, your    &lt;br /&gt;desk phone&lt;em&gt; is a&lt;/em&gt; phone, and your cell phone &lt;em&gt;is a&lt;/em&gt; phone, so both desk phone     &lt;br /&gt;and cell phone inherit their basic functionality from phone. Phone is the     &lt;br /&gt;parent (or base) class, and desk phone and cell phone are the child (or     &lt;br /&gt;derived) classes. You could draw this relationship as shown below.     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2063.image_5F00_491EF075.png"&gt;&lt;img style="border-right-width:0px;margin:0px 0px 0px 20px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/5710.image_5F00_thumb_5F00_13A8BF01.png" width="363" height="401" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;When you inherit from a class, all the properties and methods in the     &lt;br /&gt;base class are available to the derived class, just as if the properties and     &lt;br /&gt;methods were in the derived class. So the desk phone can perform the     &lt;br /&gt;answer method, as can the cell phone, even though the implementation     &lt;br /&gt;for answer is defined in the base phone class.&lt;/p&gt;  &lt;p&gt;Any class in the .NET Framework that is not intentionally sealed    &lt;br /&gt;(marked as not inheritable) can be a used as a base class. So you can inherit     &lt;br /&gt;the functionality of the .NET Framework classes in your application.     &lt;br /&gt;You can also use any class in your application as a base class and inherit     &lt;br /&gt;from it.&lt;/p&gt;  &lt;p&gt;You can see inheritance in action as soon as you create your first form.    &lt;br /&gt;When you create a form, Visual Studio generates the following code:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#&lt;/strong&gt; (in the TimeSheetWin.cs file):&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public partial class TimeSheetWin: Form&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB&lt;/strong&gt; (in the TimeSheetWin.Designer.vb file):&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Partial Class TimeSheetWin      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Inherits Windows.Forms.Form&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB, the &lt;strong&gt;Inherits&lt;/strong&gt; keyword specifies that your form inherits from the .NET     &lt;br /&gt;Framework’s Windows.Forms.Form class. In C#, a colon separates the class name from the base class, which again is the Form class. This Form class provides all the common code required to make your form work like a Windows form.&lt;/p&gt;  &lt;p&gt;NOTE: In VB, the designer file is, by default, hidden from view in Solution Explorer. To see the designer files for a VB project, select the project in Solution Explorer and then click on the Show All Files button in the Solution Explorer toolbar. Repeat the process to hide the files.    &lt;br /&gt;    &lt;br /&gt;As you define the classes for your application, you may find that some     &lt;br /&gt;classes have a number of the same properties and methods but also have     &lt;br /&gt;some properties and methods that are different. You can extract the common     &lt;br /&gt;properties and methods into another class and then use that class as     &lt;br /&gt;a base class.&lt;/p&gt;  &lt;p&gt;For example, you may find that each of your business object classes    &lt;br /&gt;(such as Employee and TimeSheet) requires a property to keep track of     &lt;br /&gt;the dirty state (added, updated, deleted). You can build a business object     &lt;br /&gt;base class that contains this property instead of adding it to every class.     &lt;br /&gt;Every business object class can then inherit from this base class and therefore have this property.&lt;/p&gt;  &lt;p&gt;[For a code example of a business object base class, see &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx" target="_blank"&gt;this link&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;Using inheritance can minimize the amount of repeated code in your    &lt;br /&gt;application. Common code is written only once in the base class and is     &lt;br /&gt;reused by every derived class. Inheritance also makes your derived classes     &lt;br /&gt;easier to build and maintain, because the derived classes focus exclusively     &lt;br /&gt;on the features that make them unique. And if you ever need to change     &lt;br /&gt;that common code, you have to change it in only one place.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>What is a Class?</title><link>http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-a-class.aspx</link><pubDate>Mon, 31 Aug 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1719745</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;Humans like to classify things, to find similarities in things, and to group    &lt;br /&gt;them accordingly. Things with similar attributes (&lt;strong&gt;properties&lt;/strong&gt;) and behaviors     &lt;br /&gt;(&lt;strong&gt;methods&lt;/strong&gt;) are grouped. In object-oriented terminology, the definition of     &lt;br /&gt;the properties and methods that describe a particular classification is called     &lt;br /&gt;a &lt;strong&gt;class&lt;/strong&gt;. A class defines a particular &lt;strong&gt;object type&lt;/strong&gt;. You can think of a class as a     &lt;br /&gt;blueprint, providing the details of how objects of that type are made.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of OO, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-oo.aspx" target="_blank"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;A cookie cutter is another analogy often used to illustrate the relationship    &lt;br /&gt;between objects and a class. The cookie cutter is the class and     &lt;br /&gt;provides the definition; it specifies the size and shape. The cookies are the     &lt;br /&gt;objects created from the cookie cutter class.&lt;/p&gt;  &lt;p&gt;For example, an employee class can have name, address, and occupation    &lt;br /&gt;properties. Sam Smith and Jessica Jones are both objects from the     &lt;br /&gt;employee class. Likewise, a time sheet class can have employee, date, and hours properties and a calculate pay method. Each person’s weekly time     &lt;br /&gt;sheet is then an object from the time sheet class.&lt;/p&gt;  &lt;p&gt;A specific object created from a class is called an &lt;strong&gt;instance&lt;/strong&gt; of the     &lt;br /&gt;class. Each instance can have values for the defined set of properties and     &lt;br /&gt;can perform the defined methods. So Sam is an instance of the employee     &lt;br /&gt;class, and Jessica’s time sheet for last week is an instance of the time sheet     &lt;br /&gt;class.&lt;/p&gt;  &lt;p&gt;The set of properties and methods described by a class are often called    &lt;br /&gt;class &lt;strong&gt;members&lt;/strong&gt;. A class defines the members, including the actual code to     &lt;br /&gt;maintain the property values and perform the methods. Each object that     &lt;br /&gt;is an instance of that class can execute the methods and retain values for     &lt;br /&gt;each property.&lt;/p&gt;  &lt;p&gt;A class itself normally does not maintain state, meaning that it normally    &lt;br /&gt;does not have any property values. Nor does it normally execute the class     &lt;br /&gt;methods. Instead, the class defines the properties and contains the implementation of the methods that are used by each &lt;em&gt;object&lt;/em&gt; created from the     &lt;br /&gt;class. Each object has values for the properties and performs the methods.     &lt;br /&gt;You do not eat the cookie cutter or fill out a time sheet class. You eat each     &lt;br /&gt;cookie and fill out each individual time sheet.&lt;/p&gt;  &lt;p&gt;The .NET Framework itself is composed of a set of classes. For    &lt;br /&gt;example, the button in the Visual Studio Toolbox represents a Button     &lt;br /&gt;class. Each time you add a button to a form, you create an instance of     &lt;br /&gt;that Button class. The Button class has specific defined methods, such     &lt;br /&gt;as Focus, and properties, such as Name and Text. The Button class     &lt;br /&gt;itself does not have a value for the Name or Text properties. Nor can it     &lt;br /&gt;have focus. Instead, it contains the implementation of the Name and Text     &lt;br /&gt;properties and the Focus method. The Button objects that you create as     &lt;br /&gt;instances of that Button class have values for the Name and Text properties     &lt;br /&gt;and perform the Focus method.&lt;/p&gt;  &lt;p&gt;Code you write normally resides in a class. If you type some    &lt;br /&gt;code in a form, your code is in the form’s class. Even if you write code in a     &lt;br /&gt;Visual Basic module, the code compiles as a class!&lt;/p&gt;  &lt;p&gt;If you have never created a class, the following example may help you    &lt;br /&gt;visualize the code for a TimeSheet class.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public class TimeSheet      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public Employee CurrentEmployee { get; set; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public decimal TotalHours { get; set; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; private DateTime _WeekEndingDate;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public DateTime WeekEndingDate       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { return _WeekEndingDate; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (value &amp;gt; DateTime.Now.Date)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new Exception(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Date must be on or before today&amp;#39;s date&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _WeekEndingDate = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public decimal CalculatePay()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return CurrentEmployee.HourlyRate * TotalHours;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:      &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Class TimeSheet      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Private _CurrentEmployee As Employee       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property CurrentEmployee() As Employee       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _CurrentEmployee       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As Employee)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CurrentEmployee = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _TotalHours As Decimal      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property TotalHours() As Decimal       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _TotalHours       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As Decimal)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _TotalHours = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _WeekEndingDate As DateTime      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property WeekEndingDate() As DateTime       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _WeekEndingDate       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As DateTime)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If value &amp;gt; Now.Date Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Throw New Exception( _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Date must be on or before today&amp;#39;s date&amp;quot;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _WeekEndingDate = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Function CalculatePay() As Decimal      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return CurrentEmployee.HourlyRate * TotalHours       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Function       &lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;The first line defines the class’s scope and name. In this case, the class     &lt;br /&gt;is named TimeSheet and is public.&lt;/p&gt;  &lt;p&gt;The next set of code defines the private data, called &lt;strong&gt;backing fields&lt;/strong&gt;, and public accessors that provide access to that data. This follows the concept of encapsulation. For example, the private _WeekEndingDate backing field variable contains the value of the time period property. Since this variable is private, it is hidden and cannot be accessed except from within this class. The public WeekEndingDate Property statement implements the get time period and set time period functionality. Any code that needs to set or get the time period uses this public property.&lt;/p&gt;  &lt;p&gt;NOTE: The C# code uses &lt;strong&gt;auto-implemented properties&lt;/strong&gt; for the TotalHours and CurrentEmployee. Auto-implemented properties are a short-cut for defining a backing field with its associated accessor. The compiler defines the private backing field for you. You can use auto-implemented properties any time you don&amp;#39;t need extra code, such as validation, in your property statement. (VB is getting auto-implemented properties in VB 10 that is coming with VS 2010.)&lt;/p&gt;  &lt;p&gt;By implementing properties using private backing fields and public    &lt;br /&gt;Property statements, you can associate code with the setting or retrieval     &lt;br /&gt;of the data value. In the WeekEndingDate example, the code that sets the     &lt;br /&gt;date validates the date before assigning it.&lt;/p&gt;  &lt;p&gt;The code at the end of the class in the preceding example demonstrates    &lt;br /&gt;a method—in this case, a function that calculates the pay. In Visual     &lt;br /&gt;Basic, methods are implemented with functions or subroutines. In C# the syntax is the same for both functions and subroutines.&lt;/p&gt;  &lt;p&gt;To access the properties and use the methods of a class, you normally    &lt;br /&gt;begin by creating an instance of the class and storing a reference to that     &lt;br /&gt;instance in an object variable. You then use that object variable to get or     &lt;br /&gt;set properties and execute methods on the resulting object.     &lt;br /&gt;The following code uses the &lt;strong&gt;new&lt;/strong&gt; keyword to create a new object from     &lt;br /&gt;the TimeSheet class. It then sets the properties on the object and executes     &lt;br /&gt;the CalculatePay method on the object.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;TimeSheet ts = new TimeSheet();      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;decimal totalPay;      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;ts.CurrentEmployee = Jessica; //Jessica is an Employee object      &lt;br /&gt;ts.WeekEndingDate = new DateTime(2009, 8, 20);       &lt;br /&gt;ts.TotalHours = 51;       &lt;br /&gt;totalPay = ts.CalculatePay();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim ts As New TimeSheet      &lt;br /&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim totalPay As Decimal        &lt;br /&gt;&lt;/font&gt;ts.CurrentEmployee = Jessica &amp;#39;Jessica is an Employee object       &lt;br /&gt;ts.WeekEndingDate = #8/20/2009#       &lt;br /&gt;ts.TotalHours = 51       &lt;br /&gt;totalPay = ts.CalculatePay&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;new&lt;/strong&gt; keyword creates a new instance of the TimeSheet class, and     &lt;br /&gt;a reference to that instance is stored in the defined object variable (ts).     &lt;br /&gt;Using the object variable and a period, the remainder of the code sets the     &lt;br /&gt;object’s properties and calls the method to calculate the pay.&lt;/p&gt;  &lt;p&gt;As stated earlier in this section, objects normally maintain state (property    &lt;br /&gt;values) and execute methods. The class itself normally does not maintain     &lt;br /&gt;state or execute methods. However, .NET does support static     &lt;br /&gt;class data and static class methods.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Static class data&lt;/strong&gt; (also called &lt;strong&gt;shared data&lt;/strong&gt;) is data that the class     &lt;br /&gt;retains, independent of any object. Use static class data any time you want     &lt;br /&gt;to retain data that is shared between all objects, such as to keep a count of     &lt;br /&gt;the total objects created from a class.&lt;/p&gt;  &lt;p&gt;A &lt;strong&gt;static class method&lt;/strong&gt; (also called a &lt;strong&gt;shared method&lt;/strong&gt;) is a method     &lt;br /&gt;that can be executed independent of any object. Static class methods are     &lt;br /&gt;good for utility functions when you don’t need to perform a process on     &lt;br /&gt;any particular object. The MessageBox and Debug classes in the .NET     &lt;br /&gt;Framework both have static class methods, so you don’t need to create an     &lt;br /&gt;instance of the class to use the methods.&lt;/p&gt;  &lt;p&gt;NOTE: If you write code in a Visual Basic module instead of a class, all the properties and methods in the module are static. You cannot create an instance from a module.&lt;/p&gt;  &lt;p&gt;Building code as individual classes logically separates the code, with    &lt;br /&gt;each class defining its own data and implementing its own methods.     &lt;br /&gt;Having code organized into logical classes makes finding code for maintenance and enhancements effortless and produces a system that is much easier to extend. It also simplifies testing and debugging, because you can test each class as an independent unit. By using OO, you can manage the complexity of your application.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>What Are Objects?</title><link>http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-are-objects.aspx</link><pubDate>Mon, 31 Aug 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1719736</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;Objects are things. People, companies, employees, time sheets, and ledger    &lt;br /&gt;entries are all types of objects. In object-oriented terms, the word &lt;strong&gt;object&lt;/strong&gt;     &lt;br /&gt;is used to describe one specific thing, such as Sam Smith the carpenter at     &lt;br /&gt;3322 Main Street and the May 15th time sheet for Jessica Jones.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of OO, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-oo.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;Objects have data associated with them called &lt;strong&gt;properties&lt;/strong&gt;. Sam Smith     &lt;br /&gt;has a name, occupation, and address. The time sheet has an employee     &lt;br /&gt;name, time period, and hours worked.     &lt;br /&gt;    &lt;br /&gt;NOTE: In object-oriented literature, properties are sometimes called &lt;strong&gt;attributes&lt;/strong&gt;, &lt;strong&gt;resources&lt;/strong&gt;, or even just &lt;strong&gt;data&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Objects also &lt;em&gt;do&lt;/em&gt; things. The time sheet is filled out, validated, and     &lt;br /&gt;submitted for payment. In real life, we fill out time sheets, validate them,     &lt;br /&gt;and submit them for payment. In a computer system, the time sheet can     &lt;br /&gt;perform these operations for itself. The things an object can do are defined     &lt;br /&gt;with &lt;strong&gt;methods&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;NOTE: In object-oriented literature, methods are also called &lt;strong&gt;behaviors&lt;/strong&gt;,     &lt;br /&gt;&lt;strong&gt;services&lt;/strong&gt;, &lt;strong&gt;operations&lt;/strong&gt;, or &lt;strong&gt;responsibilities&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Objects can be real-world things, such as an employee or time sheet.    &lt;br /&gt;Objects can be conceptual things, such as an engineering process or payroll.     &lt;br /&gt;Objects can also be implementation-specific things, such as forms,     &lt;br /&gt;controls, and DataSets. The same object-oriented concepts apply regardless     &lt;br /&gt;of whether the object is based on the real world, on a concept, or on     &lt;br /&gt;the implementation.&lt;/p&gt;  &lt;p&gt;Since objects are fundamental to understanding object orientation,    &lt;br /&gt;it is important that you can recognize objects and define their appropriate     &lt;br /&gt;properties and methods. So take a moment to think about the things     &lt;br /&gt;around you. What objects do you see? How would you define their properties     &lt;br /&gt;and methods?&lt;/p&gt;  &lt;p&gt;Your phone has properties such as color, volume, and mute. It has    &lt;br /&gt;methods such as increase volume, decrease volume, turn on mute, turn off     &lt;br /&gt;mute, dial, answer, and transfer. An employee has properties such as name,     &lt;br /&gt;address, and occupation. An electronic time sheet has properties such as     &lt;br /&gt;employee name, date, and hours. It has methods such as calculate pay.&lt;/p&gt;  &lt;p&gt;An object’s property values should not be directly accessed by something outside the object. For example, the time period should not be adjusted except through a get time period method, and the employee name would not be retrieved except through a get employee name method. This concept of hiding the internal data is a part of what is called &lt;strong&gt;encapsulation&lt;/strong&gt; and is a key premise of object-oriented programming. &lt;/p&gt;  &lt;p&gt;Every object is of a specific type. For example, the object defined as    &lt;br /&gt;Sam Smith the carpenter at 3322 Main Street is an employee object type,     &lt;br /&gt;and the May 15th time sheet for Jessica Jones is a time sheet object type.     &lt;br /&gt;All the objects of a particular type have the same set of properties and     &lt;br /&gt;methods.&lt;/p&gt;  &lt;p&gt;From a programming perspective, you can define your own object    &lt;br /&gt;types using classes. Or you can use the object types provided in the .NET Framework. In either case, you first create an object of the desired type, and then you can set or get the object’s properties and call its methods.&lt;/p&gt;  &lt;p&gt;The following code creates an object using the .NET Framework    &lt;br /&gt;&lt;strong&gt;Timer&lt;/strong&gt; object type. It then sets the object’s &lt;strong&gt;Interval&lt;/strong&gt; property to define     &lt;br /&gt;how often the timer goes off and executes its &lt;strong&gt;Start&lt;/strong&gt; method to start the     &lt;br /&gt;timer.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Timer myTimer = new Timer();      &lt;br /&gt;myTimer.Interval = 1000;       &lt;br /&gt;myTimer.Start();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim myTimer As New Timer      &lt;br /&gt;myTimer.Interval = 1000       &lt;br /&gt;myTimer.Start()&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;new&lt;/strong&gt; keyword in the first line of code creates a new Timer object     &lt;br /&gt;and assigns a reference to that new object to the myTimer object variable.     &lt;br /&gt;To access a property or method of the new Timer object, use the object     &lt;br /&gt;variable and a period (.) and then the name of the property or method.&lt;/p&gt;  &lt;p&gt;NOTE: When you type the object variable name and a period in Visual Studio,    &lt;br /&gt;you see a list of the properties, methods, and events that are appropriate for that object. This demonstrates the List Members feature of Intellisense. &lt;strong&gt;Intellisense&lt;/strong&gt; provides auto-completion and display of class documentation within Visual Studio as you are coding. &lt;/p&gt;  &lt;p&gt;Everything in .NET can be accessed as an object: forms, strings,    &lt;br /&gt;even integers. Check out this code:&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;int i = new int();      &lt;br /&gt;string s;       &lt;br /&gt;i = 5;       &lt;br /&gt;s = i.ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim i As New Integer      &lt;br /&gt;Dim s As String       &lt;br /&gt;i = 5       &lt;br /&gt;s = i.ToString&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The first line creates a new Integer object and assigns it to i. The variable    &lt;br /&gt;i is then assigned a value of 5. The last line calls the ToString method of     &lt;br /&gt;the Integer object to convert the number to a string.&lt;/p&gt;  &lt;p&gt;NOTE: Even though you can use the &lt;strong&gt;new&lt;/strong&gt; keyword to create integers, it is not     &lt;br /&gt;necessary and is not commonly done in practice. It is shown in this example to illustrate that you can work with simple data types as objects.&lt;/p&gt;  &lt;p&gt;In .NET, an integer and other primitive data types, such as Boolean    &lt;br /&gt;and decimal, are called &lt;strong&gt;value types&lt;/strong&gt;. Value types store and pass their contents     &lt;br /&gt;by their actual value. Technically speaking, value types are allocated     &lt;br /&gt;either on the stack or inline in a structure. A standard set of value types     &lt;br /&gt;are built into the .NET Framework, such as integer and decimal. You can     &lt;br /&gt;also create your own value types. You do not need to use the new keyword     &lt;br /&gt;for any value type.&lt;/p&gt;  &lt;p&gt;More complex data types in .NET, such as strings and arrays, are    &lt;br /&gt;&lt;strong&gt;reference types&lt;/strong&gt;. Reference types store and pass their contents as a reference to the value’s memory location. Technically speaking, reference types     &lt;br /&gt;are allocated on the memory heap. The .NET Framework provides a set of     &lt;br /&gt;built-in reference types, such as string and array. Classes that you create are reference types.&lt;/p&gt;  &lt;p&gt;.NET automatically creates a boxed value type for each value type when necessary. Boxed value types allow value types to be accessed like reference types (such as the preceding integer example). In addition, boxed value types    &lt;br /&gt;allow you to convert value types to reference types. For example, adding     &lt;br /&gt;to the preceding code example, you could assign the integer to an object.     &lt;br /&gt;This converts the integer value type to an object reference type.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;object o;      &lt;br /&gt;o = i;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim o As Object      &lt;br /&gt;o = i&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This conversion of value types to reference types and vice versa is    &lt;br /&gt;called &lt;strong&gt;boxing&lt;/strong&gt;. Boxing has a performance hit, so you want to minimize the     &lt;br /&gt;amount of boxing in your application wherever possible.&lt;/p&gt;  &lt;p&gt;Variables that are value types each have their own copy of the data.    &lt;br /&gt;Therefore, operations on one variable do not affect other variables.     &lt;br /&gt;Variables that are reference types, such as object variables, can refer to the     &lt;br /&gt;same object. Therefore, operations on one variable can affect the same     &lt;br /&gt;object referenced by another variable. Check this out:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Timer myTimer = new Timer();      &lt;br /&gt;myTimer.Interval = 1000; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Timer myTimer2;      &lt;br /&gt;myTimer2 = myTimer;       &lt;br /&gt;myTimer2.Interval = 500; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Debug.WriteLine(myTimer.Interval); // Displays 500      &lt;br /&gt;Debug.WriteLine(myTimer2.Interval); // Displays 500&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim myTimer As New Timer      &lt;br /&gt;myTimer.Interval = 1000       &lt;br /&gt;      &lt;br /&gt;Dim myTimer2 As Timer       &lt;br /&gt;myTimer2 = myTimer       &lt;br /&gt;myTimer2.Interval = 500       &lt;br /&gt;      &lt;br /&gt;Debug.WriteLine(myTimer.Interval) &amp;#39; Displays 500       &lt;br /&gt;Debug.WriteLine(myTimer2.Interval) &amp;#39; Displays 500&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;This code creates a new Timer object, assigns it to the myTimer object     &lt;br /&gt;variable, and sets its Interval property to 1000. It then defines a second     &lt;br /&gt;myTimer2 object variable, assigns it to the same Timer object, and sets the     &lt;br /&gt;Interval property to 500.&lt;/p&gt;  &lt;p&gt;Since myTimer and myTimer2 are object variables, they are reference    &lt;br /&gt;types. Assigning one object variable to another object variable sets     &lt;br /&gt;both variables to reference the same object. Changing the properties     &lt;br /&gt;using either object variable makes the changes to the underlying object.     &lt;br /&gt;Hence, the sample code results in 500 for both myTimer.Interval and     &lt;br /&gt;myTimer2.Interval.&lt;/p&gt;  &lt;p&gt;The one exception to this behavior is strings. Even though strings are    &lt;br /&gt;a reference type, assigning one string to another string copies the data so     &lt;br /&gt;that both strings do not reference the same data. This provides a more     &lt;br /&gt;natural use of strings in your application. For example:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;string employeeName ;      &lt;br /&gt;employeeName = &amp;quot;Jessica Jones&amp;quot;; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;string employeeName2;      &lt;br /&gt;employeeName2 = employeeName;       &lt;br /&gt;employeeName2 = &amp;quot;Sam Smith&amp;quot;; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Debug.WriteLine(employeeName); // Displays &amp;quot;Jessica Jones&amp;quot;      &lt;br /&gt;Debug.WriteLine(employeeName2); // Displays &amp;quot;Sam Smith&amp;quot;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim employeeName As String      &lt;br /&gt;employeeName = &amp;quot;Jessica Jones&amp;quot;       &lt;br /&gt;      &lt;br /&gt;Dim employeeName2 As String       &lt;br /&gt;employeeName2 = employeeName       &lt;br /&gt;employeeName2 = &amp;quot;Sam Smith&amp;quot;       &lt;br /&gt;      &lt;br /&gt;Debug.WriteLine(employeeName) &amp;#39; Displays &amp;quot;Jessica Jones&amp;quot;       &lt;br /&gt;Debug.WriteLine(employeeName2) &amp;#39; Displays &amp;quot;Sam Smith&amp;quot;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Even though employeeName2 is assigned to employeeName and then    &lt;br /&gt;employeeName2 is changed, employeeName remains unchanged. The     &lt;br /&gt;sample code results in the display of Jessica Jones and then Sam     &lt;br /&gt;Smith.&lt;/p&gt;  &lt;p&gt;Notice also that the New keyword is not required for strings. Strings    &lt;br /&gt;were designed as a special case to make it easier and more natural to work with string variables.     &lt;br /&gt;    &lt;br /&gt;Understanding how to create an object and call its properties and     &lt;br /&gt;methods is crucial to any development with .NET.&lt;/p&gt;  &lt;p&gt;(Based on an except from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.)&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>What is OO?</title><link>http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-oo.aspx</link><pubDate>Mon, 31 Aug 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1719726</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;Today’s world of software design and development is all about managing    &lt;br /&gt;complexity. Computer-savvy users want more and more features. Software     &lt;br /&gt;products, such as Microsoft Word and Excel, set high expectations. The     &lt;br /&gt;business environment requires software to react quickly to shifting corporate     &lt;br /&gt;needs. And tools and technologies are changing faster than ever. It is     &lt;br /&gt;easy to become overwhelmed by the complexity.&lt;/p&gt;  &lt;p&gt;The key to successful software is managing this complexity—and managing    &lt;br /&gt;complexity is one of the goals of object orientation (OO).&amp;#160; &lt;strong&gt;Object-oriented&lt;/strong&gt;     &lt;br /&gt;means looking at a software system in terms of the things, or     &lt;br /&gt;objects, that are relevant to that system and how those objects interact. As     &lt;br /&gt;you design and then build your application, you can focus on one object at     &lt;br /&gt;a time, temporarily ignoring the complexities of the rest of the system.&lt;/p&gt;  &lt;p&gt;OO concepts are used in many professions. For example, when    &lt;br /&gt;designing an office, an architect thinks about working spaces, foundations,     &lt;br /&gt;frameworks, and plumbing systems. These are the real-world objects. The     &lt;br /&gt;architect does not concentrate on the process of pouring the foundation,     &lt;br /&gt;hammering nails, or connecting the plumbing, nor on the details of the     &lt;br /&gt;data, such as how much concrete or how many nails. These lower-level     &lt;br /&gt;processes and details are important but not applicable to the high-level     &lt;br /&gt;design of an office building. And without the high-level design, the processes     &lt;br /&gt;and data details are irrelevant.&lt;/p&gt;  &lt;p&gt;Object orientation does not ignore the data or the process. It combines    &lt;br /&gt;the best of a procedure-oriented view (where the focus is on the     &lt;br /&gt;process) and a data-centric view (where the focus is on the data) and adds     &lt;br /&gt;productivity concepts such as reuse, testability, and, of course, managing     &lt;br /&gt;complexity.&lt;/p&gt;  &lt;p&gt;Consider a time sheet. Using a data-centric view, the key data elements    &lt;br /&gt;are the employee name, date, and hours worked. But just looking at the     &lt;br /&gt;data does not provide the full picture of time sheet processing. Using a     &lt;br /&gt;procedure-oriented view, the focus is on the process of generating the time     &lt;br /&gt;sheet. But this does not consider the bigger picture of how the time sheet     &lt;br /&gt;fits into an overall system.&lt;/p&gt;  &lt;p&gt;From an object-oriented perspective, the time sheet has data (called    &lt;br /&gt;&lt;strong&gt;properties&lt;/strong&gt;) and processes (called &lt;strong&gt;methods&lt;/strong&gt;). It also has relationships to     &lt;br /&gt;other objects in the system, such as an employee object, a logging object,     &lt;br /&gt;a data access object, and so on.&lt;/p&gt;  &lt;p&gt;Thinking about an application in an object-oriented way makes it    &lt;br /&gt;easier to break the application into its parts (objects), focus on the most     &lt;br /&gt;important aspects of each part, and look at the relationships between those     &lt;br /&gt;parts. And since Visual Basic is now a fully object-oriented programming     &lt;br /&gt;language, using an object-oriented approach to thinking about your application makes it easier to map these thoughts into object-oriented code.&lt;/p&gt;  &lt;p&gt;Excerpt from &amp;quot;Doing Objects in Visual Basic 2005&amp;quot;.&lt;/p&gt;  &lt;p&gt;For more information on using object-oriented techniques, see the following links:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-are-objects.aspx" target="_blank"&gt;What are Objects?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/08/31/what-is-a-class.aspx" target="_blank"&gt;What is a Class?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-inheritance.aspx" target="_blank"&gt;What is Inheritance?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/01/what-is-an-interface.aspx" target="_blank"&gt;What is an Interface?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/09/01/basic-pillars-of-an-object-oriented-system.aspx" target="_blank"&gt;Basic Pillars of an Object-Oriented System&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/06/applying-oop-to-simple-games-mastermind.aspx" target="_blank"&gt;Applying OOP to Simple Games: MasterMind&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx" target="_blank"&gt;Building a Business Object Base Class&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>Building an Alarm Class</title><link>http://msmvps.com/blogs/deborahk/archive/2009/08/27/building-an-alarm-class.aspx</link><pubDate>Thu, 27 Aug 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1718734</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;The specifics of this class demonstrate how to build an alarm. You can use this class to build an alarm clock application, or to add an alarm feature into your application, similar to the Reminder feature in Outlook.&lt;/p&gt;  &lt;p&gt;OR you can just use this class as an example of raising events from a business object or displaying sounds asynchronously.&lt;/p&gt;  &lt;p&gt;Build the Alarm class as follows.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;// Declare a delegate     &lt;br /&gt;public delegate void AlarmWentOffHandler(object sender, EventArgs e);      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;     &lt;br /&gt;public class Alarm      &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // Declare an event      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public event AlarmWentOffHandler AlarmWentOff; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public DateTime? AlarmTime { get; set; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private Timer AlarmTimer { get; set; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public int SnoozeInterval { get; set; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public Alarm() : this(null, 5)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&amp;#160; }      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public Alarm(DateTime? timeForAlarm): this(timeForAlarm, 5)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&amp;#160; }      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public Alarm(DateTime? timeForAlarm, int minutesToSnooze)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Set the properties      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTime = timeForAlarm;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SnoozeInterval = minutesToSnooze; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Start the timer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer = new Timer() {Interval = 10000,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Enabled = true};      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer.Tick += CheckAlarm;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void Snooze()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Reset the alarm by the snooze interval      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTime = DateTime.Now.AddMinutes(SnoozeInterval); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Reset the timer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer.Enabled = true;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; protected virtual void OnAlarmWentOff(EventArgs e)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (AlarmWentOff != null)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmWentOff(this, e);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private void CheckAlarm(object sender,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EventArgs e)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Check whether alarm time has been reached      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (AlarmTime &amp;lt;= DateTime.Now)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Disable the timer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer.Enabled = false; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Raise the event     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; OnAlarmWentOff(new EventArgs());      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Class Alarm     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Event AlarmWentOff(ByVal sender As Object, ByVal e As EventArgs) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _AlarmTime As DateTime?     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property AlarmTime() As DateTime?      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _AlarmTime      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As DateTime?)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _AlarmTime = value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _AlarmTimer As Timer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Private Property AlarmTimer() As Timer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _AlarmTimer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As Timer)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _AlarmTimer = value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _SnoozeInterval As Integer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property SnoozeInterval() As Integer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _SnoozeInterval      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As Integer)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _SnoozeInterval = value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Sub New()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Set Defaults      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Me.New(Nothing, 5)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Sub New(ByVal timeForAlarm As DateTime?)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Set Defaults      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Me.New(timeForAlarm, 5)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Sub New(ByVal timeForAlarm As DateTime?, _     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ByVal minutesToSnooze As Integer)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Set the properties      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTime = timeForAlarm      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SnoozeInterval = minutesToSnooze &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Start the timer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer = New Timer With {.Interval = 10000, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; .Enabled = True}      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AddHandler AlarmTimer.Tick, AddressOf CheckAlarm      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Sub Snooze()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Reset the alarm by the snooze interval      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTime = Now.AddMinutes(SnoozeInterval) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Reset the timer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer.Enabled = True      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private Sub CheckAlarm(ByVal sender As Object, _     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ByVal e As EventArgs)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Check whether alarm time has been reached      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If AlarmTime &amp;lt;= Now Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Disable the timer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AlarmTimer.Enabled = False &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Raise the event     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RaiseEvent AlarmWentOff(Me, New EventArgs())      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; End Sub     &lt;br /&gt;End Class&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The C# code begins by declaring a delegate for its event. This is not required in the VB code since the delegate is handled for you.&lt;/p&gt;  &lt;p&gt;Within the class, the C# and VB code declare an event called &lt;strong&gt;AlarmWentOff&lt;/strong&gt;. This is the event that is generated when the alarm goes off.&lt;/p&gt;  &lt;p&gt;The class has three properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;AlarmTime&lt;/strong&gt;: Time that the alarm should go off.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;AlarmTimer&lt;/strong&gt;: A private property that manages the timer for checking the alarm time.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;SnoozeInterval&lt;/strong&gt;: The alarm can optionally be set to snooze. This is the amount of snooze time in minutes.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The C# code uses auto-implemented properties and the VB code uses the expanded property syntax. (VB is getting auto-implemented properties in VB 10.)&lt;/p&gt;  &lt;p&gt;The constructors for the class optionally define the alarm time and minutes to snooze. The constructor then starts the timer that goes off every 10 seconds. (This can be adjusted as desired. Or the timer interval could be defined as a property of this Alarm class.)&lt;/p&gt;  &lt;p&gt;The class has one public method: &lt;strong&gt;Snooze&lt;/strong&gt;. The Snooze method adds the snooze interval amount to the AlarmTime to reset the alarm. It also ensures that the timer in enabled.&lt;/p&gt;  &lt;p&gt;Each time the timer goes off, the code checks the current time against the alarm time. If the alarm time has been reached, the code disables the timer and raises the &lt;strong&gt;AlarmWentOff&lt;/strong&gt; event.&lt;/p&gt;  &lt;p&gt;This class can be used whenever you need to add an alarm, notification, or reminder to your application. Here is an example of how this class is accessed.&lt;/p&gt;  &lt;p&gt;NOTE: It uses a .wav file for the alarm and plays it using the built-in SoundPlayer.&lt;/p&gt;  &lt;p&gt;Start by adding this to the top of your code file.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;using System.Media;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Imports System.Media&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Then add the following code somewhere in your user interface.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Alarm myAlarm;     &lt;br /&gt;private void SetTheAlarm()      &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // Create an alarm object      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; myAlarm = new Alarm(DateTime.Now.AddMinutes(1), 1);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; myAlarm.AlarmWentOff +=&amp;#160; AlarmWentOff;      &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;private void AlarmWentOff(object sender, EventArgs e)     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; var player = new SoundPlayer(&amp;quot;myFile.wav&amp;quot;);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; player.PlayLooping();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; DialogResult replay =       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBox.Show(&amp;quot;Wake up&amp;quot; +       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Environment.NewLine +       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Yes to wake up.&amp;quot; +       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Environment.NewLine +       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;No to snooze.&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Alarm Clock&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBoxButtons.YesNo,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBoxIcon.Exclamation);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; player.Stop();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (replay != DialogResult.Yes)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; myAlarm.Snooze();      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim myAlarm As Alarm     &lt;br /&gt;Private Sub SetTheAlarm()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Create an alarm object      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; myAlarm = New Alarm(Now.AddMinutes(1), 1)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AddHandler myAlarm.AlarmWentOff, AddressOf AlarmWentOff      &lt;br /&gt;End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private Sub AlarmWentOff(ByVal sender As Object, ByVal e As EventArgs)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim player As New SoundPlayer(&amp;quot;myFile.wav&amp;quot;)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; player.PlayLooping()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim replay As DialogResult = _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBox.Show(&amp;quot;Wake up&amp;quot; &amp;amp; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Environment.NewLine &amp;amp; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Yes to wake up.&amp;quot; &amp;amp; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Environment.NewLine &amp;amp; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;No to snooze.&amp;quot;, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Alarm Clock&amp;quot;, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBoxButtons.YesNo, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBoxIcon.Exclamation)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; player.Stop()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; If replay &amp;lt;&amp;gt; DialogResult.Yes Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; myAlarm.Snooze()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;End Sub&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;This code defines a variable that references the Alarm class. In a SetTheAlarm method, the class creates an instance of the class, passing in an alarm time and snooze interval.&lt;/p&gt;  &lt;p&gt;For testing, this is set to 1 minute from the current time and the snooze is set to one minute. In most cases, you would want to get the alarm time from the user.&lt;/p&gt;  &lt;p&gt;When the alarm goes off, this code plays a .wav file using the SoundPlayer provided in .NET. Be sure to change the .wav file name to the directory and file name of a .wav file on your system.&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;PlayLooping&lt;/strong&gt; method of the SoundPlayer is used to play the sound continuously. This method is asynchronous, so the code will continue to the next line.&lt;/p&gt;  &lt;p&gt;The example displays a message box, allowing the user to cancel the alarm or snooze the alarm. In either cause, the code calls the Stop method of the SoundPlayer to stop the .wav file. If the user requested to snooze, it calls the alarm&amp;#39;s &lt;strong&gt;Snooze&lt;/strong&gt; method.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item><item><title>Building a Business Object Base Class</title><link>http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx</link><pubDate>Tue, 21 Jul 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1704681</guid><dc:creator>DeborahK</dc:creator><description>&lt;p&gt;If you are building applications in .NET to manage data for a business, you are most likely creating business object classes. Depending on the business, these classes could include Customer, Product, Order, Invoice, PurchaseOrder, Employee, TimeCard and so on.&lt;/p&gt;  &lt;p&gt;A simple sample Customer class is shown &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/03/generics-building-a-list-of-customers.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;There are some features that all business objects need to support. For example:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Entity State: The business object needs to track whether it is new, updated, or deleted so it can make the appropriate change to the database. &lt;/li&gt;    &lt;li&gt;Validation: Is the current data defined for the business object valid? &lt;/li&gt;    &lt;li&gt;Save: Saves the changes to the database. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Notice that data retrieval functionality is not included in this list. That is because in most cases, you may never retrieve a single business object. Rather, you would retrieve a set of them. For example, all active orders or all customers with overdue invoices. So the retrieve functionality is not included in the class that manages a single object. (Most on this in a later post.)&lt;/p&gt;  &lt;p&gt;Instead of repeating this common functionality in each business object, it makes sense to build a base class. Each business object can then inherit from this base class to share this common functionality.&lt;/p&gt;  &lt;p&gt;So let’s get started.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;using System;      &lt;br /&gt;using System.ComponentModel;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public abstract class BoBase :      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IDataErrorInfo,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; INotifyPropertyChanged       &lt;br /&gt;{       &lt;br /&gt;      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Imports System.ComponentModel      &lt;br /&gt;      &lt;br /&gt;Public MustInherit Class BOBase       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Implements IDataErrorInfo       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Implements INotifyPropertyChanged       &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The class is abstract (MustInherit in VB) to indicate that it is meant to be a base class and not to be used on its own. An abstract class cannot be instantiated directly, so no other code can create an instance of the class.&lt;/p&gt;  &lt;p&gt;The class then implements two interfaces:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;IDataErrorInfo: This interface provides error information that the user interface can use to report validation errors to the user. It works well with the ErrorProvider control provided in WinForms and supports ASP.NET and WPF features. &lt;/li&gt;    &lt;li&gt;INotifyPropertyChanged: This interface ensures that the user interface is notified when a property value changes, keeping your business object and user interface in sync. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We’ll look at the implementation of these interfaces shortly.&lt;/p&gt;  &lt;p&gt;First, define the valid set of entity states.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected internal enum EntityStateType      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Unchanged,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Added,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Deleted,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Modified       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Friend Enum EntityStateType      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Unchanged       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Added       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Deleted       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Modified       &lt;br /&gt;End Enum&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The Enum is declared Protected because the entity state should only be accessible from the business object itself. However, Internal (Friend in VB) was added so that related objects (such as Order and OrderLineItem) could reference the related object state.&lt;/p&gt;  &lt;p&gt;The business object state is retained using an EntityState property.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected EntityStateType EntityState { get; private set; }&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _EntityState As EntityStateType      &lt;br /&gt;Protected Property EntityState() As EntityStateType       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _EntityState       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Private Set(ByVal value As EntityStateType)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _EntityState = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;This property is protected, but the setter is private. So the business objects that inherit from this class can read the entity state, but only the base class can set the value.&lt;/p&gt;  &lt;p&gt;Additional properties provide a way to get the entity’s state in an easier fashion. These properties are not required, but they make the base class a little easier to use.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BindableAttribute(false)]      &lt;br /&gt;[BrowsableAttribute(false)]       &lt;br /&gt;public bool IsDirty       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return this.EntityState != EntityStateType.Unchanged; }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BindableAttribute(false)]      &lt;br /&gt;[BrowsableAttribute(false)]       &lt;br /&gt;public bool IsNew       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return this.EntityState == EntityStateType.Added; }       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;BindableAttribute(False)&amp;gt; _      &lt;br /&gt;&amp;lt;BrowsableAttribute(False)&amp;gt; _       &lt;br /&gt;Public ReadOnly Property IsDirty() As Boolean       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return Me.EntityState &amp;lt;&amp;gt; EntityStateType.Unchanged       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;BindableAttribute(False)&amp;gt; _      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;BrowsableAttribute(False)&amp;gt; _      &lt;br /&gt;Public ReadOnly Property IsNew() As Boolean       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return Me.EntityState = EntityStateType.Added       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The IsDirty and IsNew properties are public, so they can be accessed from anywhere. They are marked with two attributes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Bindable: Defines whether the property should be used for binding. In this case the value is false because the user interface should not be able to bind to this property. &lt;/li&gt;    &lt;li&gt;Browsable: Defines whether the property should be displayed in the Properties window. Again, the value is false. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Two other properties handle the validation.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BindableAttribute(false)]      &lt;br /&gt;[BrowsableAttribute(false)]       &lt;br /&gt;public bool IsValid       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return (ValidationInstance.Count == 0); }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected Validation ValidationInstance { get; set; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt; &lt;font color="#65402e" face="Consolas"&gt;&amp;lt;Bindable(False)&amp;gt; _&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;lt;BrowsableAttribute(False)&amp;gt; _     &lt;br /&gt;Public ReadOnly Property IsValid() As Boolean     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return (ValidationInstance.Count = 0)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get     &lt;br /&gt;End Property &lt;/font&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _ValidationInstance As Validation      &lt;br /&gt;Protected Property ValidationInstance() As Validation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _ValidationInstance       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Private Set(ByVal value As Validation)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _ValidationInstance = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Again, the public property is marked with the Browsable and Bindable attributes. The ValidationInstance property retains an instance of the Validation class for the business object. The code for the Validation class is &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/16/validation-class.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The constructor creates an instance of the Validation class.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected BoBase()      &lt;br /&gt;{&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160; ValidationInstance = new Validation();       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Sub New()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ValidationInstance = New Validation      &lt;br /&gt;End Sub&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The following is the implementation of IDataErrorInfo.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#region IDataErrorInfo Members &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BrowsableAttribute(false)]      &lt;br /&gt;[BindableAttribute(false)]       &lt;br /&gt;public string Error       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return ValidationInstance.ToString(); }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BrowsableAttribute(false)]      &lt;br /&gt;[BindableAttribute(false)]       &lt;br /&gt;public string this[string columnName]       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return ValidationInstance[columnName]; }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#endregion&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#Region &amp;quot; Properties required by the IDataErrorInfo&amp;quot;      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Bindable(False)&amp;gt; _&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;BrowsableAttribute(False)&amp;gt; _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public ReadOnly Property [Error]() As String _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Implements IDataErrorInfo.Error       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return ValidationInstance.ToString       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;BrowsableAttribute(False)&amp;gt; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Bindable(False)&amp;gt; _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Default Protected ReadOnly Property Item(ByVal columnName _&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; As String) As String _&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Implements IDataErrorInfo.Item       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return ValidationInstance.Item(columnName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property       &lt;br /&gt;      &lt;br /&gt;#End Region&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;Error&lt;/strong&gt; property uses the overridden ToString method of the validation class to return the full list of validation errors.&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;Item&lt;/strong&gt; property provides access to the validation errors given a property name. This property is implemented as the class indexer in C#.&lt;/p&gt;  &lt;p&gt;The following in the implementation of INotifyPropertyChanged.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#region INotifyPropertyChanged Members     &lt;br /&gt;public event PropertyChangedEventHandler PropertyChanged;      &lt;br /&gt;#endregion&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#Region &amp;quot; Events required by INotifyPropertyChanged&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Event PropertyChanged(ByVal sender As Object, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ByVal e As System.ComponentModel.PropertyChangedEventArgs) _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Implements INotifyPropertyChanged.PropertyChanged      &lt;br /&gt;#End Region&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This interface only defines a single event. This event should be raised whenever the data is changed.&lt;/p&gt;  &lt;p&gt;Since every business object will have unique requirements for the save operation, the &lt;strong&gt;SaveItem&lt;/strong&gt; method is not implemented. Rather it is defined as abstract.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public abstract Boolean SaveItem();&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public MustOverride Function SaveItem() As Boolean&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Defining an abstract (MustOverride in VB) SaveItem method ensures that every business object has a SaveItem method.&lt;/p&gt;  &lt;p&gt;Finally, since the EntityState property setter is private, the base class needs a method to set the entity state.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected internal void SetEntityState(EntityStateType newEntityState)     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; switch (newEntityState)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EntityStateType.Deleted:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EntityStateType.Unchanged:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EntityStateType.Added:      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.EntityState = newEntityState;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; default:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (this.EntityState == EntityStateType.Unchanged)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.EntityState = newEntityState;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected internal void SetEntityState(EntityStateType newEntityState, string propertyName)     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SetEntityState(newEntityState);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (PropertyChanged != null)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PropertyChanged(this,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;new PropertyChangedEventArgs(propertyName));     &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Friend Sub SetEntityState(ByVal dataState As EntityStateType)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SetEntityState(dataState, Nothing)      &lt;br /&gt;End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Friend Sub SetEntityState( _     &lt;br /&gt; ByVal newEntityState As EntityStateType, ByVal propertyName As String)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Select Case newEntityState      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Case EntityStateType.Deleted, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EntityStateType.Unchanged, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EntityStateType.Added      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Me.EntityState = newEntityState &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Case Else     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If Me.EntityState = EntityStateType.Unchanged Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Me.EntityState = newEntityState      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Select &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; If Not String.IsNullOrEmpty(propertyName) Then     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim e As New PropertyChangedEventArgs(propertyName)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RaiseEvent PropertyChanged(Me, e)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;End Sub&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;SetEntityState&lt;/strong&gt; method has two overloads. The first is used when changing the entity state in general and the second is used when changing the entity state because a specific property is changed.&lt;/p&gt;  &lt;p&gt;For example, when setting an object as Unchanged, Added, or Deleted, it does not matter which property was changed. But when a particular property is changed, the code must also raise the PropertyChanged event.&lt;/p&gt;  &lt;p&gt;In this case, the C# and VB code was implemented differently. In the C# code, the code to set the entity state is in the first overload. The second overload then calls the first and then raises the event.&lt;/p&gt;  &lt;p&gt;In the VB code, the first overload simply calls the second overload. The second overload then sets the entity state and then raises the event as appropriate. You can use either technique in either language.&lt;/p&gt;  &lt;p&gt;That’s it! You now have a base class that can be used with any business object class. If you have any other common functionality, you can add it to this base class. &lt;/p&gt;  &lt;p&gt;Here is an example of how you use this base class.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public class Customer : BoBase     &lt;br /&gt;{      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private string _LastName;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string LastName      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _LastName; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_LastName == null || _LastName != value)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;LastName&amp;quot;;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Validate the last name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateClear(propertyName);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateRequired(propertyName, value); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, propertyName);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public override Boolean SaveItem()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // TODO: Add code here      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Class Customer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Inherits BoBase&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _LastName As String     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property LastName() As String      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _LastName      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As String)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _LastName Is Nothing OrElse _LastName &amp;lt;&amp;gt; value Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;LastName&amp;quot;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Validate the last name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateClear(propertyName)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateRequired(propertyName, value) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, propertyName)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Overrides Function SaveItem() As Boolean     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; TODO: Add code here      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Function      &lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Notice how the class statement includes the syntax to inherit from BoBase. The LastName property uses the ValidationInstance defined in the base class to validate the value. It also sets the entity state when the last name is changed.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;</description></item></channel></rss>