Now that we have analyzed the activities and interfaces of the online shop, we can start breaking the functionality into modules. Some functions will be needed across many forms, and it is useful to encapsulate those functions into utility classes. For example, parsing the XML product catalog will be necessary for almost every activity:
In this section we break down the functional items into modules and develop a class diagram for Online Photo Shop. Figure 11.4 shows the class diagram of the Web application part of Online Photo Shop.
Figure 11.4. Class Diagram for Online Shop
11.3.1 The Product Parser
Because parsing the XML product catalog is needed across almost every aspect of the online store, we create a utility class with simple high-level API functions that return the list of all products, the list of options for a given product, and the complete set of information stored in the XML file with each product or option item.
11.3.2 The Shopping Cart
Another area that stretches across multiple forms is the shopping cart. The .NET Framework provides containers and lists from which the shopping cart can be inherited. Because each item in this online store is customizable by personal images, we must create a unique identifier for each item in the shopping cart. This unique identifier lets us associate each ordered item with its own digital image. We will create a class that encapsulates all information stored with an ordered item, including the following:
Storing the image location on the client lets us later display the images quickly and easily in the shopping cart. We could downsize the uploaded images to a thumbnail size and send them back for display, but we have a better plan. We directly specify the path of the image on the client, along with the desired display size, in the shopping cart form, and have Internet Explorer take care of the downsizing.
Because we must use unique identifiers for each shopping cart item, it makes sense to inherit the shopping cart from a hash table collection, which offers fast access to all the elements using the unique identifier. According to the requirement C:online_shop_stateservice, the information stored in the shopping cart must also be serializable so that we can transfer it to the ASP.NET State server. To fulfill this requirement, both the class implementing the shopping cart and the class representing a shopping item must inherit from ISerializable and must implement the serialization methods.
Furthermore, we encapsulate functionality that deals with the display of the shopping cart items in a dedicated class (ShoppingItemView). This class formats a shopping cart item for display in a data list. For example, this class translates product and option codes of a shopping cart item into a name and a description.
11.3.3 Web Forms
The Web forms that must be implemented in this iteration are the product browser and the shopping cart view. We create both forms using Visual Studio.NET. These forms inherit from the .NET Framework class System.Web.UI.Page and use code behind technology to separate program logic from HTML design.
Following the revised project plan described at the beginning of this chapter, we have decided to address the checkout process in the next iteration. However, while we are breaking the functionalities into modules we can already see that it's a good idea to encapsulate all the algorithms that we use to compute the tax and shipping cost. Tax and shipping cost may vary regionally and may change over time. It is therefore a good idea to split these functional items into separate classes for easier maintenance.
Introducing Software Engineering
A .NET Prototype
The Photo Editor Application
GDI+ Graphics Extensions
Advanced GDI+ Operations
Dynamic Loading of Components
Accessing System Resources
Performance Optimization, Multithreading, and Profiling
Building the Web Application with ASP.NET
Security and Database Access