Moving from procedural programming languages such as ASP and Visual Basic to .NET object-oriented languages enables programmers to build systems that are highly extensible and flexible. In the first part I will demonstrate how to isolate business rules to a particular implementation class.The ScenarioI have built an application that tracks bills for a company. I host the application for the company and perform modifications for a fee. A second company likes the product but adds new business rules in calculating the bill. The second company has requested a modification to the application to meet their business need.Version 1 - VB Com Object
Public
using
ExplanationThe Bill class provides the basic design of the system. Most customers should want the functionality of the base Bill class. New customers who want additional functionality and class members can request objects that are derived from the base Bill class. In the sample above, the base class Bill calculates the bill by (# of products * price of Products). When a customer wants to modify this functionality, I create a new implementation class CompanyBBill that inherits all of the functionality of the Bill class. I inherited from Bill instead of creating a new class so that CompanyBBill will maintain all of the functionality of the original Bill. Thus, I do not have to rewrite getDiscountPrice().The BillFactory class provides an intermediate between the client and the implementation class. If a customer requests a change you could make a new implementation class and alter the factory for the base class. If this technique was applied across all business objects, a customer could request functionality that changed in only one or multiple business objects.Applying to the Real WorldIn future articles I will demonstrate how to expand this concept.1) Building a user interface of dynamically loaded Web User Controls from a factory. The same patterns could be applied so that the user interface adapts to each customer needs and changes.2) Have each Business Object that is changeable derive from a base class. This base class will have a collection of generic data objects driven by a database. Coding specific implementations into class files. The class files can be compiled at first run and cached on the server for future use. The class files will add functionality by overriding functionality in a base class and potentially accessing the generic data objects above. Once this framework is established you can do the following: a) Release customer functionality with zero regression testing for other customers. b) Publish your application and limited object model to customers and have their programmers alter functionality without having access to your base code. You can even charge for object models with different levels of detail!! c) Publish new versions of the application without affecting the base build. d) Remove functionality of old customers with zero impact.