Component-based .NET software development
Foreword With the rapid advancement of software technology, modern large software has widely used software components. Guided by mature CBD (Component Based Design: Component) Theory is guided, after the analysis and design of the system, the system development is reflected in multiplexing existing components, developing new components, and assembling all components. . J2EE uses a variety of components to share a complex enterprise information system to achieve huge success. As a later, .NET Framework draws J2EE's successful experience, there is a unique design in component development, in this article, we will introduce the most important two categories of .NET component development technology: mixed language development and Component reflection. The author has a sufficient reason to believe that the reader will definitely admire the design and developers of .NET Framework after understanding the powerful component development function of .NET, and will provoke the interested interest in developing software systems. Mixed language development Java language cross-platform design, is an important reason for J2EE to occupy an advantage in enterprise systems. In order to compete with J2EE, .NET Framework uses a layered design pattern in design architecture, thus theoretical The platform has become possible (in fact, there is a real-available system, MONO is .NET Framework) that runs on the non-Windows operating system ,. NET designers also found a dead point of J2EE - J2EE components must be used Java language development! This kind of "dictators" in this language undoubtedly makes programmers who love other languages very unhappy. To this end, .NET first considers the development of mixed language in the design of software development platform, in the eyes of the author, this is really a profound technology change. This article is not intended to fully introduce the internal mechanism of mixed language in .NET Framework, just from the application perspective, through several short but typical instances to see how we integrate multiple languages in a project. Net components.
Component's combination When we need to multiplexed the functionality of existing components to develop new systems, we often allow new development components to easily include another component to achieve code reuse, this development mode is The object design theory is called "combination". Let's take a small example: We want to design a C # component, and its interface is shown in Figure 1:
Figure 1 UML illustration of C # Component Opens the VS.NET, create a CSHARPComponent, delete the original class1, add a new class CSharpClass to the project, add a function Saysomething, the code is as follows:
Public void saysomething (String STR)
{
Messagebox.show ("This is the function of C # implementation, the incoming string is:" STR);
} Then, select "Generate" à "Generate Solution" from the menu, generate a dynamic link library after compiling: csharpclass.dll. Now, we have a reusable software component, although its function is not worth mentioning, but it is indeed a software component, in essence, there is no difference between the commercial components selling thousands of US dollars. . Here we need to be clear: csharpclass.dll can actually refer to the component library, and class CSHARPCLASS can be seen as a component that can be multiplexed. Obviously, a component library (DLL file) can accommodate multiple components (ie, a class that completes a function). Then we create a Windows application project, but then we use it no longer C #, but VB.NET. We named the project: vbtestComponent, dragging a button into the form from the toolbox, we intend to call the Saysomething () method in the C # component CsharpClass.dll when the user clicks this button. Send a string from VB to this method. In order to use the development of good C # components, we must add a reference to CsharpClass.dll to the VB project. On the Solution Resource Manager window: Right-click on VbTestComponent, select from the pop-up menu: "Add a reference ...", the following form will appear: Figure 2 Add a reference to C # Components CsharpClass.dll, click ... Browse ... "Button, find CSHARPCLASS.DLL, after the determination is shown in Figure 2. Click the "OK" button to close the window, now we add a reference to the C # component to the VB project, you can see this in the Solution Explorer window: Figure 3 adds to the C # component reference The things behind the "Solution Manager" are very simple, write the following code in the click event:
Private sub button1_click_1 (...) Handles Button1.click
Dim obj as csharpclassnamespace.csharpclass
Obj = new csharpclassnamespace.csharpclass ()
Obj.SAYSMETHING ("I appeared from the method of calling C # components from VB.")
End Sub
OK, we now realize the function of calling C # components in VB, which is simply too simple! Smart, then the melon must be turned: Since it can be so easy to adjust the C # components from VB, then it is also necessary. Or, I can do a VB component, then, it calls a C # component, and the C # component can call a component of a C development, ..., adjust the transfer, and one. Contemporary Yugong: "The child is still in the end of the year, why do you still don't have to force all programmers in a project now, and allocate a separate component to each other. Let them develop in their favorite languages, just follow the prior custom interface. The author recalls that using VB to call the Win32 API, can't help but cheer the painful days are not returned!