Implementing the Web Application or Service


Implementing the Web Application or Service

After being tasked to develop some business functionality, the first action a developer will need to take is to create a structure from which to build the code. Depending on the version of Visual Studio 2005 Team System you're using, you might or might not have the ability to automatically generate the code for a Web application or Web service inside of Visual Studio. Visual Studio 2005 Team Edition for Software Architects includes a graphical tool called the Application Designer, which can be used to graphically architect a solution. With a simple right-click, code can be generated from the tool that includes the entire appropriate infrastructure. The application connection diagram can be seen in Figure 6-2.

A very cool feature of the application diagram is that you can set many settings and constraints on each of the components. For instance, you can constrain a Web service to run only on a machine that supports Internet Information Server 6 and .NET Framework version 2.0. You can also specify which language should be used when generating the code skeleton from the application diagram.

If you're using Visual Studio 2005 Team Edition for Software Developers, you won't be able to create code from the architectural diagrams. If that's the case, you'll need to depend on the architect to have generated the appropriate skeleton code for you. However, if you have Team Edition for Architects installed or are using the Team Suite edition, you'll be able to do everything the architect is able to do, including generating skeleton code from the application diagram. Either way, at some point you might have a basic, skeleton code structure with all the appropriate connection points to other services already defined.

figure 6-2 an application diagram

Figure 6-2 An application diagram

After you have the appropriate skeleton code, you then must implement the business logic and desired functionality. If the architect has generated the code skeleton, the first step is to check out the code from version control. You can then begin implementing the actual code.

There are a few cases where you might actually be creating your own framework. Primarily, this is when you're designed a class, or set of classes, that will be compiled into a dynamic-link library (DLL). Although there are no architectural designers to aid in the building of a DLL as a whole, you can use the Class Designer to work on individual classes and interfaces.

Using the Class Designer

There are a couple different ways to create code in Visual Studio 2005 Team System. You can write code as text or you can graphically create code using the Class Designer. The Class Designer provides a graphical interface for creating code. Unlike a “round trip” code engineering tool that generates code from a graphical representation and can, in turn, modify the graphical representation when the code changes, the Class Designer is the code. It's a purely graphical representation of the code structure. Although the difference between these two different methods might seem small, conceptually there is a great deal of difference. First, the text itself is treated as the code and the graphical representation is treated only as a representation. This mistakes the text of the code as the code itself, but in fact it's the only possible representation of the code. Although traditionally software code has been represented by text, this is by no means a requirement, and the conceptual step of treating code as functionality and having many possible representations of that functionality is one of the reasons why the Class Designer is important.

The Class Designer itself is technically not an exclusive part of Visual Studio 2005 Team System; it's also included in the other versions of Visual Studio 2005. As such, we might be taking a little detour discussing it here. However, it's so useful for developing code that we need to talk about it!

The Class Designer has many excellent features that can improve both the speed of development and the quality of the resulting code. Seeing the code visually allows you to quickly ensure that there is a clean relationship between the classes and that the class inheritance hierarchies are of a reasonable depth. In addition, you can use graphical features to create new classes, add new properties and methods to those classes, and set up relations between classes.

To get to the class diagram, you can either add a new one to the project or simply right-click the project and select View Class Diagram. Figure 6-3 shows a simple class diagram of a Dog class, an inherited Beagle class, and also an Owner class that is related to the Dog class. Note that the connection between Owner and Dog is an association relationship, and it has a label with the word “Dog” above it. The Class Designer was smart enough to know about the relationship between the two classes, based on an examination of the classes. The Owner class has a public property called Dog, which references a private instance of the Dog class. This property was automatically generated when the association was made!

figure 6-3 a simple class diagram created using the class designer

Figure 6-3 A simple class diagram created using the Class Designer

Another powerful feature of the class diagram is the ability to quickly use the Object Test Bench. The Object Test Bench is a fast tool to create an instance of a class so that you can test its features easily, without having to whip up a quick Microsoft Windows® application and some lines of code to create an instance and call it. Simply right-click on any class diagram, and choose the Create Instance menu item. You are then prompted to name the soon-to-be-created instance. (See Figure 6-4.)

figure 6-4 naming the instance

Figure 6-4 Naming the instance

You can now use the Object Test Bench to call any of the methods on the class. In Figure 6-5, you can see how easy it is to graphically call the Bark method on the Beagle class. Prior to the Bark method actually being invoked, you get the option to specify any input parameters that are necessary. In the case in Figure 6-5, there are no parameters, so the Bark method can execute without additional information. The return value can then be saved as a value in the Object Test Bench so that it can be used later, possibly as an input to another method call.

figure 6-5 using the object test bench to implement methods

Figure 6-5 Using the Object Test Bench to implement methods

The Class Designer also allows you to do a fair amount of refactoring directly inside the graphical interface. For instance, back in Figure 6-3, there was an inheritance hierarchy with a Dog class. If you wanted to extract an interface from the Dog class, you would simply right-click the Dog element, choose Refactor, and then select Extract Interface. A wizard then walks you through a few steps, allowing you to select which elements of the Dog class you want to be included in the interface. The interface is then created in code, and your Dog class is changed to reflect an implementation of the created interface.

There are a few other things to mention about the Class Designer. As noted previously, it's a part of Microsoft Visual Studio 2005 Standard Edition, not just Team System, so many people will have access to it. In addition, it's not a Unified Modeling Language (UML) diagram tool. The Class Diagram uses a very easy to learn and convenient graphical representation of code that helps maximize the development speed and quality of class code.



Working with Microsoft Visual Studio 2005 Team System
Working with Microsoft Visual Studio 2005 Team System (Pro-Developer)
ISBN: 0735621853
EAN: 2147483647
Year: 2006
Pages: 97

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net