Library tutorials & articles

Visual Studio Next Generation: Language Enhancements

Encapsulation

Encapsulation means that developers can contain and hide information about an object, such as internal data structures and code. It isolates the internal complexity of an object's operation from the rest of the application.

For example, when you set the Caption property on a command button, you don't need to know how the string is stored. Visual Basic will help you do this by letting you declare properties and methods as private protected or public.

Why would you want to protect class members? Let's assume that certain properties of a class represented an object's state. If you couldn't prevent those properties from being accessed directly from outside the class, how could you ever guarantee the state of that object? If you protect the property, you could then create a custom method that would be used to assign values to that property. The method could contain validation code to ensure that the value is set properly. Since the property value is assigned in just one place, the code becomes much easier to debug and maintain. In the example below, "me" refers to a specific instance of a class.

Protected cName as string
Protected Function ChangeName(NewName)
    Me.cName = NewName
End Function

Comments

  1. 12 Nov 2002 at 17:10

    The Object Oriented feature like Inheritance,Polymorphism,Encapsulation in Visual Basic is really a great achievement.Offcourse making a VB program as Multithreaded and allowing STructured exception handling is other great achievements.


    But I beleive there is a potential drawback associated with VB.That is its languag construct.SImultaneously there should be effort in improving the Construct/Style of VB language.
    Otherwise there will be a learning curve for any object oriented C++/Java developer to use VB.
    It cannot be called as a ObjectOriented language unless the Construct of the language is similar to any of the ObjectOrieneted Language.


    Ghanshyam.

  2. 01 Aug 2002 at 21:18

    I am not sure if you have your whole VB history down. I learned VB from a Version 2.0 Demo. Also, did you also know there was Visual Basic for DOS?

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Visual Studio Next Generation: Language Enhancements.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media

    CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...

Related jobs

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!