So what makes .NET and this new framework different from its competitors and warrants its use for this project? Why was .NET even selected by Company ABC over C++, aside from the obvious " time-to-market " advantages? How did the patterns presented in this book help with that? Why are design principles more important now with .NET than they ever have been in the past with traditional Microsoft languages? Finally, all of the questions accumulated from the previous chapters will be answered here. That is why I even went through the trouble of telling you about this product in the first place. Showing a real commercial application's architecture is the best the way to hammer this stuff home from theory to reality. No more simple e-commerce storefront examples, no more "Adventure Works" demos, and no more Microsoft "Northwind" examples. Major apologies to Microsoft because these well-known demo applications are great, but I thought presenting an application that was generating revenue would be even better. So let me begin to answer these questions.
Why is .NET a Competitive Advantage?
When I was contracted by Company ABC to look into converting its existing framework to .NET, my first response was to ask why. I knew several reasons but I wanted to know why they wanted to do this. Company ABC's lead architect's response was "time to market" and "flexibility." It takes only a few demonstrations to realize why this is true. Time to market is important for all vendors , so I'm not going to rehash the obvious. But what makes .NET and its design potential so flexible is exactly what I will be talking about. With C++, you have the means of creating truly sophisticated and robust applications but unfortunately , the investment in time, resources, and money is also great. With Visual Basic, you can decrease this investment with the added risk of possibly poorly designed applications or one that is inflexible to customization. For those Visual Basic programmers who are laughing at this statement, try on .NET for one year, then go back Visual Basic 6.0; enough said.
Microsoft .NET bridged those worlds for Company ABC by providing the technological means for designing a truly robust, flexible, and sophisticated backbone using resources that already exist and without throwing manpower and money at the effort. The flexibility I'm talking about rests in more than the features and Web service creation capabilities that the .NET framework provides. It's about the runtime environment and the languages themselves . Microsoft finally has a purely object-oriented environment to call its own. I think the market misses this with .NET in all of the Web services media it generates. The framework is much more than Web services.
The framework provides a truly object-oriented development environment with XML at the core . However, this also presents a challenge to the existing developers out there, especially those mired in technology without any care for sound design. To borrow a corny phrase from the movie Spiderman , "with great power comes great responsibility." With .NET, Web Services, and simplified distributed and object-oriented computing with XML, it has never been true more than it is today. The design is now more than ever the key.
Everyone talks about design flexibility but I see very few designs that actually feature it. How many frameworks have you seen that were truly simple to maintain? For the customers of Company ABC, this type of flexibility is what they were referring to when answering my earlier "why" question. As mentioned in the product backgrounder, electronic check processing and all of the payment products must easily integrate with existing accounting packages. They must be integrated quickly, and they must be flexible enough to withstand constant change because these accounting packages change almost annually in version, in rules, and in feature set. This does not refer to flexibility only on the front end. For Company ABC, it is even more important that flexibility be seen on the back end or middle tier , as well.
The system that was delivered provided this flexibility, and it did so without sacrificing simplicity. For example, the time I spent transferring the code to those who now had to support it couldn't have been any easier. In fact, I spent only about three days doing code walkthroughs. The rest of the system was picked up through documented designs (using Rose), a simple yet effective architecture, and the documentation generated from comments all throughout the code. The autodocumentation features of Visual Studio .NET alone saved me countless hours. I guess this is a cautionary tale for those who are looking for unethical job security.
Payment processing rules change monthly, and with the myriad of financial processors out there, the change is neverending. For example, NACHA submits rules updates every few months. This means that the financial processors (the people behind the banks) must change how they interpret a checking transaction. These constant rule changes mean the companies running the financial transactions through must also be aware of those changes. The companies that purchase ProductX want to be able to adapt to those new rules, so that software must be flexible enough to withstand this change in all areas of the system. This is primarily one of the reasons you see so many financial institutions adopting .NET. For more proof, go the http://msdn.microsoft.com/vstudio/productinfo/casestudies/ and see the myriad of financial case studies out there featuring .NET.
The payment processing software must be flexible enough on both the front end and the back end to anticipate these changes without requiring a software update from Company ABC. This has presented a challenge to Company ABC and led to the importance of leveraging some of the flexibility and robustness built into the .NET framework (e.g., Web services, Reflection, XML schemas, etc.). In fact, you probably have noticed that most of the patterns presented in this book center around achieving this flexibility. From the data tier and the Poly Model to the Unchained Web Service Factory, building a fungible architecture is the key to success in this business, as it is in most.
Some of new architecture features of the Commercial Framework not supported in the existing COM framework that was to be bridged included the following:
Initially, this product will include a full bridge to the legacy system for those not yet installing .NET on their server systems or on their workstations. This new product will support the existing legacy product using a bridgelike COM Interop layer to communicate with all back-end COM components. This Interop layer will utilize the .NET COM/API Interop layer as part of the new .NET framework in the first release. A full migration of all original features will constitute the second release of the Commercial Product and include full credit card features.
Without using .NET, many of these things would be rather complicated to design and write. Now I just assume their existence in every major framework I build. It's very easy to get spoiled and forget how much effort had to be put forth in order to receive these niceties. Things such as dynamic data tiering are provided by using Poly Models and must be designed. However, leveraging items such as XML schemas and SOAP support make your job all that much easier. Dynamic error logging, dynamic configuration, and remote tracing are all covered in Chapter 2 and all leverage many built-in implementation patterns that the Commercial Framework offers.
Hopefully, you appreciate by now that the .NET base class libraries are not simple "api wrapper" libraries. They have been designed with patterns "baked in," mostly at the implementation level. Base class library features such as asynchronous networking and Web services are all built on the Observer pattern. Delegate patterns are used everywhere, as you saw in Chapters 3 and 4. Loose coupling, adaptors, and factories are all baked into the .NET framework ”some design- and some implementation-focused. Take a look at how some of the libraries were delivered, and you'll see a plethora of best practices that you get to leverage in your code every day.
So let's dive a little deeper into the technology advantages of .NET and what specifically helped Company ABC achieve its robust "poly architecture," if you will. First I need to describe briefly the main modules or features from this product's architecture. These modules are areas of the architecture that were either migrated to .NET or created from scratch.
Table 6.1 shows necessary plumbing for most frameworks that were applied in this case.
Table 6.1. Major architectural features of the commercial framework
Many of the architecture components described in Table 6.1 are discussed here. From a logic flow perspective, the call originates from the left side of the diagram from a managed or unmanaged test client. This is a placeholder class to show that any managed client can be used to call into the framework using one of the Web Service Factory patterns. A Web Service Factory is implemented by the Chained and Unchained Service Factory (Chapter 4) and is the entry point into the framework. Any of the payment products can be executed from this point, using standardized methods to invoke the business component (more on this in the next section). From the Web Service Factory, a call is made to instantiate the correct Service Fa §ade (e.g., PaymentFacade) that in turn uses the Product Manager to instantiate the correct product.
Once the product (e.g., ProductX) is created, it further delegates its logic to the more specific objects. These child or aggregated objects from the Product Manager are business-specific and contain the rules that drive the originally requested action. Any action can be requested, as long as the request is encapsulated using the appropriate XML schemas. For every requested business function, there is an XML schema specific to that area. The only schema that is used for all business components is a schema called the decision schema. The decision schema simply contains the "verbs" (to borrow an old but effective COM vernacular) that are used by the framework to instantiate the correct Service Fa §ade, instantiate the correct product, and invoke the correct method.
A decision schema looks like the following (Listing 6.1):
Listing 6.1 Example metadata-oriented decision schema for routing messages and invoking downstream business objects in the service factories of the framework.
<xs:element name="DECISION"> <xs:complexType> <xs:sequence> <xs:element name="TYPE" type="xs:string" minOccurs="0" /> <xs:element name="ACTION" type="xs:string" minOccurs="0" /> <xs:element name="SERV" type="xs:string" minOccurs="0" /> <xs:element name="SERVER" type="xs:string" minOccurs="0" /> <xs:element name="SUBTX" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element>
The instance data for the decision schema informs the Web Service Factory what the client wants the framework to do. Creating this meta-language for our framework allows me to use one or two entry methods into the system and prevents future Web service signature changes from affecting its clients. The Web Service Factory's job is to read the decision schema's instance data and instantiate the appropriate Service Fa §ade. From there, the packet is translated into something the framework will recognize, and the drum beats on.
When the packet reaches the Product Manager, the framework begins to delegate from the generic to the specific. From this point, the framework elements are used only in support of the specific business objects that drive products residing on top the framework. ProductX is an example of one of those products. ProductX resides within the Product Manager hierarchy, and from its ProductX class it drives the rules that give ProductX its life. The components that support the reusable features of ProductX, such as exception handling, are those for which these patterns are presented. This "plumbing" and the patterns used are what I will cover in the next section. Many of the architecture services covered should be very familiar.
In fact, most of the Commercial Framework consists of roles you typically see in most frameworks: