Based on the component. NET software development (1)

Source: Internet
Author: User
Tags mixed reference
Based on the component. NET software development


Objective
With the rapid progress of software technology, modern large-scale software has been widely used in software components based development methods. Based on the theory of mature CBD (Component Based Design: Component based system), after analyzing and designing the system, the system development is embodied as the process of reusing existing components, developing new components and assembling all components. Java EE Large-scale use of a variety of components to construct a complex enterprise information system, has achieved great success.

As a successor, the. NET framework draws on the successful experience of Java EE and has its own unique design in component development, which we will introduce in this article. NET component development technology is the most important two categories: hybrid language development and component reflection. The author has good reason to believe that the reader is understanding. NET, the design and developers of the. NET Framework will be admired and the application will be aroused. NET to develop a strong interest in software systems.

Mixed language development
The design of Java language cross-platform is an important reason for the advantage of EE in enterprise class system, in order to compete with Java EE, the. NET framework adopts a layered design pattern on the design architecture, which theoretically makes cross-platform possible (in fact, there are actually available systems, Mono is the. NET framework that runs on a non-Windows operating system. NET designers also found that a dead point of Java EE--J2EE components must be developed in the Java language! This use of the language "dictatorship" undoubtedly makes the program members who love other languages unhappy. To this end,. NET in the history of software development for the first time in the design of software operating platform to consider the hybrid language development, in my opinion, this is a far-reaching technological change.

This article does not intend to fully introduce the internal mechanism of mixed language development in the. NET framework, but only from an application perspective, through a few short but typical examples, to see how we integrate multiple languages in a project. NET component.



Combination of components
When we need to reuse the functionality of existing components to develop new systems, we often allow newly developed components to simply accommodate another existing component in order to achieve the function of code reuse, which is called "combination" in object-oriented design theory. Let's take a look at a small example:

We're going to design a C # component whose interface is shown in Figure 1:



Figure 1 UML Diagram of C # component

Open Vs.net, create a C # class library project: Csharpcomponent, delete the original CLASS1, add a new class Csharpclass to the project, and add a function saysomething, the code is as follows:



public void saysomething (String str)

{

MessageBox.Show ("This is the function that C # implements, the passed-in string is:" +str);

}

Then, select Build from the menu, build solution, and a dynamic link library will be generated when the compilation is complete: CSharpClass.dll.

Now that we have a reusable software component, it's really a software component, which is essentially the same as the commercial components that sell thousands of of dollars.

Here we need to be clear: CSharpClass.dll can actually be called a component library, while class Csharpclass can be viewed as a reusable component. Obviously, a component library (DLL file) can hold multiple components (that is, a class that completes a function).

We then create a Windows Application project, but instead of using C #, we vb.net. We named the project as: vbtestcomponent, drag a button from the Toolbox onto the form, and we intend to call the SaySomething () method in the C # component CSharpClass.dll directly when the user clicks the button. and send a string from VB to this method.

In order to be able to use the developed C # component, we must add the reference to the CSharpClass.dll to the VB project. In the Solution Explorer window, in the project node: vbtestcomponent Right click, select from the pop-up menu: "Add Reference ...", the following form appears:


Figure 2 Adding a reference to the C # component CSharpClass.dll

Click the "Browse ..." button to find CSharpClass.dll, as shown in Figure 2. Click the OK button to close the window, and now we have added a reference to the VB project to the C # component that you can see clearly in the Solution Explorer window:



Figure 3 Adding the solution manager after a reference to a C # component



The next thing is simple, write the following code in the Click event of the button:



Private Sub button1_click_1 (...) Handles Button1.Click

Dim obj as Csharpclassnamespace.csharpclass

obj = New Csharpclassnamespace.csharpclass ()

Obj. SaySomething ("I came from VB calling methods in the C # component.) ")

End Sub



OK, we now realize the function of calling C # component in VB, this is simply too simple!

Smart you now must be turning the brain: since VB can be so easy to tune the C # components, then, in turn also certain lines. Or, I can do a VB component, and then, it calls a C # component, and the C # component can invoke a C + + developed components, ..., adjust to transfer, seamless. The contemporary Yu Gong yue: "The posterity is endless also, what worry project finish?!" ”

Now don't force all programmers to use one language in a project, give each individual a separate component and let them develop it in their favorite language, as long as they follow a predetermined interface.

I recall the past use of VB to invoke the horror of the Win32 API, can not help but cheer that painful days gone forever!




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.