Actual combat:
Create a VB.NET Windows application: vbtestdynamiccomponent. Join the two class Componentlist and LoadComponents described earlier to the project.
We read the relevant assembly information and class name information from the configuration file when the program starts, add the following code to the Form_Load process of the main form:
01 Private ObjloadComponent As LoadComponent
02 private vbobj as object
03 Private ComponentReader as MyComponentlist
04
05 private sub vbtestdynamicform_load (...) Handles MyBase.Load
06 ObjloadComponent = new loadcomponent ()
07 ComponentReader = new mycomponentlist ("ComponentList.xml")
08 DIM FILENAME AS STRING
09 DIM CLASSNAME AS STRING
10 ComponentReader.beginread ()
11 filename = componentReader.getFileName (0)
12 classname = componentreader.getclassname (0)
13 DIM RET As Boolean
14 RET = ObjloadComponent.LoadComponentlibrary (filename)
15 vbobj = ObjloadComponent.loadClass (classname)
16 vbobj.show ()
17 END SUB
We see, the 07--10 sentence removes the DLL file name and class name from the configuration file, set the first DLL file name and class name, then load the component library in the 14th sentence, the 15th sentence is loaded Objects, because the object returned is actually a form, so the SHOW () method can be called directly to display this form in the 16th sentence.
You can see from the code, how places and simple to create an object in .NET! Please note: We don't even need to add references to specific components to the project! The object that is dynamically created in this example is a form, and the Form object can be used by default. In the real engineering, you can put all the interfaces into a specific DLL. I call "Facade assembly", other projects only need to reference this DLL, all components of these interfaces are free to pass the name. create!
summary
In a short message, we introduce .NET's hybrid language development characteristics and dynamic assembly component technology, showing the simple and flexibility of developing component-based applications under .NET, this is developing "hug The software system of the change provides new possibilities, which can be summarized as follows:
(1) We can block the system functions through the OOAD (Object Analysis and Design) before the development, and then assigned to different developers to develop into multiple DLLs, and finally, it is convenient to combine these components to construct a new system. Once a function is made into components, it can be constantly reused in future projects, and BUG will get less and more powerful, and the function will become more and more stable. Such components will be Very valuable technical resources.
(2) Due to the powerful component object model of the .NET, some object-oriented features of the source code level: such as inheritance and polymorphism, now can be promoted to the component level. In particular, we can also apply design patterns between components. Comrades, hurry to turn over the classic books of GOF, apply the above 24 models in the components, you will definitely feel the vastness of the software technology progress to the programmer.
(3) Through the externally saved configuration information, we can dynamically let the entire software show a completely different style and functionality without recovering the program. Think about the two forms created in our examples are the main form of the other two complex programs, which doesn't mean that our program can integrate them very conveniently? It's too simple to implement, isn't it to add one or two lines of code in the configuration file?
(4) The configuration file uses an XML standard that can easily add new properties to the elements, thereby expanding the functionality of the program. In addition, by providing DTD and Schema, verify that the file is valid before dynamically load the configuration file, and XSLT can dynamically replace the configuration file ... The flexibility and scalability of XML do not need me more Say it? This flexible application is watching you!
(4) With the above technical support, we focus on OOAD in the process of developing software, which is exactly the characteristics of object-oriented era system analysis and design.
For example, a software company needs to develop a product of a industry, it can analyze this industry service function, abstract different levels of business, where the most basic business is made to dynamically load. When you need to customize the software for a new customer in this industry, you can do with a small amount of specialized components, which can greatly improve the development efficiency. This is CBD (Component-Based Develop: Component Development).
At present, very popular MDA (Model Driven Architecture), in fact, the components are based on components, without a lot of stable components, MDA is "Drive".
The author discovers that all successful software companies, especially those lead multinational companies, such as CA, SAP, Ericsson, etc., there is a large-scale component library, and the components in the library have been strictly practical, based on Some mature components development new system, the code reuse rate is sometimes reached 80% to 90%, to achieve this degree of code reuse, requires software companies to go deep into a certain industry for more than ten years or even decades The deep accumulation, this is also the gap between the young domestic software companies and foreign first-class companies.
(5) ......
Ok, don't say more, I believe that smart readers can understand the huge power of the development of components.
Go back to .NET, Microsoft said when advertising vs.net: it greatly improved development efficiency. This is not bragging, I personally feels, using .NET development project, the technology on the traditional Win32 platform, can increase 1/3! Really in-depth study and application .NET, the author can't help but admire the scientists and engineers developing and designing .NET technology, paying attention to their creative labor. At the same time, the author also shows that China's software technology can work together, we have too much behind!