Component-based. NET software development (1)

Source: Internet
Author: User
Component-based. NET software development

 

Preface

With the rapid development of software technology, modern large-scale software is widely used based on software components. Guided by mature component based design: Component-based system design, after the analysis and design of the system, system development is embodied in the Process of reusing existing components, developing new components, and assembling all components. J2EE's large-scale use of various components to construct complex enterprise information systems has achieved great success.

As a latecomer ,. net Framework draws on the successful experiences of J2EE and has its own unique design in componentized development. In this article, we will introduce it. the two most important aspects of the net componentized development technology are hybrid language development and component reflection. I have a good reason to believe that the reader understands this. net. the Design and developers of the Net Framework are admired and will arouse the application. net to develop software systems.

Hybrid Language Development

The cross-platform design of Java language is an important reason why J2EE has an advantage in enterprise-level systems. To compete with J2EE ,. net Framework uses a hierarchical design model in the design architecture, which theoretically makes cross-platform possible (in fact, there are actually available systems, mono runs on a non-Windows operating system. net Framework ),. net designers also discovered a dead point of J2EE-the J2EE component must be developed in Java! This language-based "dictatorship" undoubtedly makes programmers who love other languages very unhappy. To this end, for the first time in the software development history,. Net considered hybrid language development when designing the software runtime platform. In my opinion, this is a profound technological change.

This article does not cover all of them. the internal mechanism of mixed language development in the. NET Framework is only from the application point of view, through a few short but typical examples, to see how we integrate multi-language development in a project.. NET component.

 

Component combination

When we need to reuse the functions of existing components to develop a new system, we often make the newly developed components simply include another existing component to achieve the function of code reuse, this development method is called "Combination" in the object-oriented design theory ". Let's take a look at a small example:

We need to design a C # component, as shown in interface 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 to the project. The Code is as follows:

 

Public void saysomething (string Str)

{

MessageBox. Show ("This is a function implemented by C #. The input string is:" + Str );

}

Select "generate" à "generate solution" from the menu. After compilation, a dynamic link library csharpclass. dll is generated.

Now we have a reusable software component. Although its functions are not worth mentioning, it is indeed a software component, essentially, it is no different from commercial components that sell for thousands of dollars.

Here we need to make it clear that csharpclass. dll can actually be called a component library, while csharpclass can be seen as a reusable component. Obviously, a component library (DLL file) can accommodate multiple components (that is, a class that completes a certain function ).

Next we will create another Windows application project, but we will not use C #, but VB. NET. We name the project vbtestcomponent and drag a button from the toolbox to the form. We plan to directly call the C # component csharpclass when you click this button. the saysomething () method in DLL, and transmits a string from VB to this method.

To use the developed C # component, we must add a reference to csharpclass. DLL to the VB project. In the Solution Explorer window, right-click the project node vbtestcomponent and select "add reference..." from the pop-up menu ...", The following form is displayed:

Figure 2 Add a reference to the C # component csharpclass. dll

Click Browse ..." Find csharpclass. dll, as shown in figure 2. Click "OK" to close the window. Now, we add a reference to the C # component to the VB project. You can see this clearly in the Solution Explorer window:


Figure 3 added the solution manager after referencing the C # component"

 

The next thing is simple. Write the following code in the button-clicking event:

 


Private sub button1_click_1 (......) Handles button1.click

Dim OBJ as csharpclassnamespace. csharpclass

OBJ = new csharpclassnamespace. csharpclass ()

OBJ. saysomething ("I came up calling methods in the C # component from VB. ")

End sub

 

OK. Now we have implemented the function of calling the C # component in VB. This is too simple!

If you are smart, your brain will surely turn around at this moment: Since the C # component can be easily adjusted from VB, then the other way around will be fine. Or, I can make a VB component, and then it calls a C # component, and the C # component can call a C ++ developed component ,......, Adjust and adjust. Contemporary yugong said: "Son, son, sun, and sun are endless. why can't the project be completed ?!"

Now, there is no need to force all programmers to use one language in a project. They can allocate an independent component to each of them so that they can develop it in their preferred language, you only need to follow the predefined interface.

I think back to the miserable times when I used VB to call Win32 APIs. I can't help but cheer that the painful days are 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.