Introduction to OOP in vb.net

zhaozj2021-02-16  45

BY budi kurniawan09 / 23/2002

Visual Basic .NET offers its users, among many other things, a fully object-oriented programming (OOP) experience. Some former VB6 developers have prepared themselves well to embrace this new version of the language. Others, however, need more time and guidance in taking on this new challenge and opportunity. in this VB.NET OOP series, Budi Kurniawan introduces many facets of object-oriented design and programming to VB programmers new to OOP. Discussions focus more on OO concepts rather than OO techniques. in the first article of this series, Budi answers what is probably the most often asked question by newcomers to OOP:? Why OOP Finally, we look at why VB6 programmers often find it hard to shift to OOP when the OOP itself is not difficult.

Microsoft launched the .NET Framework early this year and overhauled its most popular language:. Visual Basic With the introduction of the Framework, the language was reconstructed and given a new name:. VB.NET It's now a language that fully supports object-oriented programming. It is true that VB6 supported some notion of objects, but lack of support for inheritance made it unfit to be called an OOP language. for Microsoft, changing VB is more of a necessity than a choice, if VB is to become one of The .NET Framework Languages ​​and in Order for VB Programmers To Be Aable To Use The .NET Framework Class Library.

With the change to the language, many VB fans might think that OOP is a natural progression from procedural programming, and that OO technology is a new technology. Surprisingly, this is not the case. OO concepts were first introduced in 1966 in a journal paper titled "SIMULA-An Algol-based Simulation Language." Its authors, Ole-Johan Dhal and Kristen Nygaard from the University of Oslo and the Norwegian Computing Center (Norsk Regnesentral), later completed the first OOP language in the world. The language is called Simula 67, short for simulation language.You may find it hard to believe that a full-fledged OO language was implemented before structured programming and when, as OO expert Bertrand Meyer puts it in his book, Object Oriented Software Construction, "The Vietnam War was still a page 4 item; barricades had not yet sprung up in the streets of Paris;. a mini-skirt could still cause a stir "However, OO technology did not become popular until the early 1980s, because at the time of invention, it was considered too radical for practical use. VB only became a fully OOP officially in 2002 and the inventors of this technology, Ole-Johan Dhal and Kristen Nygaard, only got their Turing Award, considered the Nobel prize of computer science, IN 2001 "For ideas Fundamental to the Emergence of Object-Oriented Programming, Through Their Design of The Programming Languages ​​Simula i and Simula 67."

Why OOP?

OK, enough history. Now, let's discuss why OOP in VB is a good thing. There are many benefits of OOP that make the technology so popular and the computing science society grateful to its inventors. Below, I will mention the three most important ones , in no particular order.

Modularity is Inherent in OOPModern software applications tend to become larger and larger. Once upon a time, a "large" system comprised a few thousand lines of code. Now, even those consisting of one million lines are not considered that large. When a system gets larger, it starts giving its developers problems Bjarne Stroustrup, the father of C , once said something like this:. a small program can be written in anything, anyhow If you do not quit easily, you'll make it work,. At The end. but a large program. if you don't use technology story.

The reason for this is there is interdependency among different parts of a large program. When you change something in some part of the program, you may not realize how the change might affect other parts. Modularity makes maintenance less of a headache. Modularity is inherent in OOP because a class, which is a template for objects, is a module by itself. What is the problem for those new to OOP is how to determine what methods and data should make up a class. This is another topic of its own, though. A good design should allow a class to contain similar functionality and related data. An important and related term that is used often in OOP is coupling, which means the degree of interaction between two classes (modules).

OOP Promotes Reusability

Reusability means that code that has previously been written can be reused by the code writer and others who need the same functionality provided by the code. It is not surprising, then, that an OOP language often comes with a set of ready-to-use libraries. in the case of VB.NET, the language shares the .NET Framework Class Library with other .NET languages. These classes have been carefully designed and tested. It is also easy to write and distribute your own library. Support for reusability in a programming platform is very attractive, because it shortens the time taken to develop an application. In the world where good programmers are expensive, what else is more appealing? One of the main challenges to class reusability is creating good documentation for the class library. HOW FAST CAN A Program FIND A Class That Provides The FunctionAlity He / SHE IS LOOKING FOR? IS IT FASTER TO FIND Such A Class OR to WRITE A NEW ONE from Scratch? In the .NET Framework Class Library, Classes and Other Types Are Grouped Into Namespaces. for instance, the system.drawing namespace contains the collection of type sets buy.

VB.NET programmers are lucky, because the .NET Framework comes with good documentation, with proper indexing and structured and searchable content Reusability does not only apply to the coding phase through the reuse of classes and other types;. When designing an application in an OO system, solutions to OO design problems can also be re-used. These solutions are called design patterns, and to make it easier to refer to each solution, the pattern is given a name. For example, if you need to make sure that a class can only have one instance, there is already a solution to it, which is called the "singleton" design pattern The early catalog of reusable design pattern can be found in Design Patterns:.. Elements of Resusable Object-Oriented Software in future Articles, I WILL Also Discuss The Use of these Patterns.oop Supports Extendibility

Every application is unique. It has its own requirements and specifications. In terms of reusability, sometimes you can not find an existing class that provides the exact functionality that your application requires. However, you will probably find one or two that provide part of the functionality ....................... ..

In OOP, extendibility is achieved through inheritance. You can extend an existing class, add some methods or data to it, or change the behavior of methods you do not like. If you know the basic functionality that will be used in many cases, but you do not want your class to provide very specific functions, you can provide a generic class that can be extended later to provide functionality specific to an application.A good example is the System.Windows.Forms.Form class, which provides basic methods, properties, and events for a Windows form. To create a form in a Windows application, you extend this class. Because your application has specific requirements that do not necessarily exist in other applications' specifications, you can add the methods and data specific To your need and programing (and debugging) Efforts because you get the basic functionality of a form for free by extending system.windows.forms.form.

As another example, take a look at the Control class in the System.Windows.Forms namespace. This class provides basic functionality for a Windows control. For instance, it has the BackColor property that will be needed by all Windows controls. Other classes that Extend It get this Property for Free. Examples of classes That Extend The Control Class Are Label, Monthcalendar, Scrollbar, etc. These classes Need The Backcolor Property As Part of Their user interface.

Not every control needs the SetCalendarDimensions method, however;. Only MonthCalendar does Therefore, the designer of the .NET Framework class library did not put this method in the Control class, but in the MonthCalendar class If you create your own custom control by. Extending The Control Class, Your Class, Too, Will Get The Backcolor Property For Free.vb6 Programmers and OOP

Now, I Hope You Agree with Me That To Work WITHIN THE .NET Framework, VB Programmers Need To Master Oop. In The Light of this, There is Bad News and Good Off. The Bad News IS, The VB Versions PRIOR To VB. NET, including VBScript and Visual Basic for Applications (VBA), are not fully OOP languages ​​It is true that you could use and write COM components, which are basically objects;. this is probably the reason that some people insist that VB6 is an OOP language. The lack of other OOP features such as inheritance, however, disqualify previous versions of VB from being an OOP language (for the criteria of an OO system, see Chapter 2 of Bertrand Meyer's Object-Oriented Software Construction, Second Edition).

It is probably more appropriate to categorize the old VB into something between a procedural language and an OOP language This is bad news for those wanting to learn VB.NET Researchers have been arguing about the best way to teach OOP at school;.. Some argue That it is best to teach procedural programming. in Many Curricula, We See That The Oop Course Can Be Taken When A Student Is Nearing The Final Year of His / Her University Term.

More recent studies, however, have revealed the contrary. Michael Kolling, from the School of Computer Science and Computer Engineering, Monash University, Australia, explained in one of his papers why learning OOP seems harder learning structured programming. He and other experts argue than that it is how OOP is taught, not OOP itself, that makes it such a difficult task.Someone with procedural programming skill thinks in a paradigm very different from how OO programmers view and try to solve problems. When this person needs to learn OOP, he / she has to go through a paradigm shift. It is said that it takes six to 18 months to switch your mindset from procedural to object-oriented paradigms. Another study shows that students who have not learned procedural programming do not find OOP that difficult .

Now the good news. VB.NET is a relatively easy language to program with. VB.NET programmers do not need to worry about pointers, do not have to spend precious time solving memory leaks caused by forgetting to destroy unused objects, etc. The .NET Framework Also Comes with a Very Comprehensive Class Library ITS Early Version. Once You KNOW The Nuts and Bolts of OOP, Programming with VB.Net IS Easy.

ConclusionThis article has presented the main benefits of OOP and why procedural programmers find it hard to learn OOP OOP is great for writing many types of applications A word of caution, though:.. OOP is not everything For example, some people can not be convinced. That Using OOP IS Better At Solving Engineering Or Quantum Mechanics Problems Than Procedural Programming.

转载请注明原文地址:https://www.9cbs.com/read-27499.html

New Post(0)