Comprehensive analysis of vb.net (4)

Source: Internet
Author: User
Iv. Wide application of objects
Code reuse simplifies the development process, and features such as visual inheritance make code reuse more convenient. However, code reuse is not limited to this. With the help of the CLR (Common Language Runtime, the Common language runtime Environment) as the vb.net base, we can inherit classes written in other vb.net languages in Vs.net. For example, we could write a C # class and then inherit the C # class in the VB.net class.

Vb. NET's object-oriented function has expanded in all directions, even into the language itself--in vb.net, everything is an object. It means that we have much more support and functionality from vb.net itself than previous versions of VB, and fewer when it comes to Windows APIs. For example, in previous versions of VB, we used the LoadPicture method to load a graphic, draw lines using the line method (or some other faster API function), and in vb.net we create and process graphics with System.Drawing objects. The following code displays a graphic on a form using the System.Drawing object:


Picshowpicture. Image = _
System. Drawing.Image.FromFile (_
"C:test.bmp")



Note that VB. NET "Everything is an object" can make your code verbose. Consider the following statement, which paints a yellow-green line over a drawing object:


Objgraphics. DrawLine (System. Drawing. _
Pens.chartreuse, 0, 0, 100, 100)



The statement is longer, but the benefit is that it is more flexible and easier to use. In the past, to implement some of the more complex functions is often to delve into the documentation, often to turn to the API. All of the related feature sets are now encapsulated in the object. There are additional advantages to using the Object encapsulation feature-objects are organized in an extremely graceful form, so it is actually interesting to look at the objects and see what they are doing.

Visual Basic.NET's object-oriented features offer many tangible benefits. In most cases, VB is compared to previous versions of VB. NET object-oriented nature and its support for inheritance make it faster and more convenient to create certain types of applications. However, while we can use inheritance as well as other. NET, such as free threads, but these features are not necessarily used. As with all other languages, the features we must use are those that are most meaningful for a given situation.

Free threads may need to be specifically explained. VB6 allows you to create multithreaded services through cell threads, but VB has never supported client programs that create free threads. Vb. NET changed all of this. Now, the creation of free threading applications has been a very trivial and common thing. It is so mundane that it is perfectly predictable that some programmers will not understand the specifics of a free thread when adding it to the application. Starting a new thread takes a few lines of code-simply passing the method's address to the thread object, which starts a new thread. This is no doubt extremely practical and convenient, but it must be noted that these features are only suitable for a particular situation, that it is the responsibility of the developer to know which scenarios apply to these features and how to properly apply them. Frankly, many developers are causing trouble for themselves by abusing inheritance and free threads, and hopefully that doesn't include you.



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.