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
The Java language cross-platform design is an important reason for J2EE to occupy an advantage in an enterprise system. In order to compete with J2EE, .NET Framework uses a layered design pattern in the design architecture, which has theoretically makes cross-platform it. 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 developed in Java language ! 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 combination
When we need to multiplexed the function of the existing component to develop a new system, we often allow new development components to simply enhance another component to achieve the code reuse, this development method is in object-oriented design theory It is called "combination". Let's take a look at a small example:
We want to design a C # component, and its interface is shown in Figure 1:
Figure 1 UML illustration of C # components
Open 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, and 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 Project Node in the Solution Explorer: VbTestComponent, right-click, select from the pop-up menu: "Add a reference ...", the following form appears:
Figure 2 Add a reference to the C # component csharpclass.dll
Click the "Browse ..." button to find CSHARPCLASS.DLL, then after the determination is shown in Figure 2. Click the "OK" button to close the window, now we have added a reference to the C # component to the VB project, you can see this in the Solution Explorer window:
Figure 3 adds "Solution Manager" after the C # component reference
The next thing is 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 children of the children are endless, why do you still don't work?"
Now you don't have to force all programmers in a project in a project, so I allocate an independent component to you, let them develop with their favorite languages, just comply with 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!