IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
VB.Net
Search VB.Net Group:

Advanced
-Collapse +Expand VB.Net To/From
To/FromCODEGuides
-Collapse +Expand VB.Net Store
PRESTWOODSTORE
   ► KBProgrammingVB.NetOOP   Print This     

VB.Net KB: OOP Topic



19 Articles Found in the OOP Topic 

  KB Article    

Mike Prestwood
1. VB.Net Abstraction (MustInherit, MustOverride, Overrides)

VB.Net supports abstract class members and abstract classes using the MustInherit and MustOverride modifiers.An abstract class is indicated with a MustInherit modifier and is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties. An abstract member is either a method (implicitly virtual), property, indexer, or event in an abstract class. You can add abstract members ONLY to abstract classes using the MustOverride keyword. Then you override it in a descendant class with Overrides.

13 years ago, and updated 12 years ago
(1 Comments , last by charlos.j )

Code

Article
Nothing New Since Your Last Visit
25607
Hits

VB.Net Language

Mike Prestwood
2. VB.Net Access Modifiers

In VB.Net, you specify each class and each class member's visibility with an access modifier preceding class or member. The VB.Net access modifiers are the traditional Public, Protected, and Private plus the two additional .Net modifiers Friend and Protected Friend.

Friend indicates members are accessible from types in the same assembly. Protected Friend indicates members are accessible from types in the same assembly as well as descendant classes. OO purist might object to Friend and Protected Friend and I suggest you avoid them until you both fully understand them and have a need that is best suited by them.

13 years ago, and updated 12 years ago

Code
Nothing New Since Your Last Visit
11573
Hits

VB.Net Language

Mike Prestwood
3. VB.Net Base Class (System.Object)

In VB.Net, the Object keyword is an alias for the base System.Object class and is the single base class all classes ultimately inherit from.

13 years ago, and updated 12 years ago
(1 Comments , last by Catherine.S )

Code
Nothing New Since Your Last Visit  
11736
Hits

VB.Net Language

Mike Prestwood
4. VB.Net Class..Object (Class..End Class..New)

Declare and implement VB.Net classes after the form class or in their own .vb files. Unlike VB Classic, you can have more than one class in a .vb class file (VB classic uses .cls files for each class).

13 years ago, and updated 12 years ago

Code

KB Post
Nothing New Since Your Last Visit
15766
Hits

VB.Net Language

Mike Prestwood
5. VB.Net Constructors (New)

 A sub named New. You can overload the constructor simply by adding two or more New subs with various parameters.

Public Class Cyborg
Public CyborgName As String
Public Sub New(ByVal pName As String)
CyborgName = pName
End Sub
End Class
12 years ago

Code

KB Post
Nothing New Since Your Last Visit  
16995
Hits

VB.Net Language

Mike Prestwood
6. VB.Net Finalizer (Finalize())

Use a destructor to free unmanaged resources. A destructor is a method with the same name as the class but preceded with a tilde (as in ~ClassName). The destructor implicity creates an Object.Finalize method (you cannot directly call nor override the Object.Finalize method).

In VB.Net you cannot explicitly destroy an object. Instead, the .Net Frameworks garbage collector (GC) takes care of destroying all objects. The GC destroys the objects only when necessary. Some situations of necessity are when memory is exhausted or you explicitly call the System.GC.Collect method. In general, you never need to call  System.GC.Collect.

12 years ago, and updated 12 years ago
(3 Comments , last by marcus.t )

Code

Article
Nothing New Since Your Last Visit  
21306
Hits

VB.Net Language

Mike Prestwood
7. VB.Net Inheritance (Inherits ParentClass)

VB.Net uses the Inherits keyword followed by the parent class name. If you do not include Inherits, your class inherits from System.Object.

13 years ago, and updated 12 years ago

Code
Nothing New Since Your Last Visit  
12085
Hits

VB.Net Language

Mike Prestwood
8. VB.Net Inheritance-Multiple (Not Supported)

VB.Net does not support multiple implementation inheritance. Each class can have only one parent class (a single inheritance path). In VB.Net, you can use multiple interface usage to design in a multiple class way horizontally in a class hierarchy.

13 years ago, and updated 12 years ago

Code
Nothing New Since Your Last Visit
6541
Hits

VB.Net Language

Mike Prestwood
9. VB.Net Interfaces (Interface, Implements)

With VB.Net you define an interface with the Interface keyword and use it in a class with the Implements keyword. In the resulting class, you implement each property and method and add Implements Interface.Object to each as in:

Sub Speak(ByVal pSentence As String) Implements IHuman.Speak
MessageBox.Show(pSentence)
End Sub
13 years ago, and updated 12 years ago

Code

Article
Nothing New Since Your Last Visit
15882
Hits

VB.Net Language

Mike Prestwood
10. VB.Net Member Field

In VB.Net you can set the visibility of a member field to any visibility: private, protected, public, friend or protected friend.

You can intialize a member field with a default when declared. If you set the member field value in your constructor, it will override the default value.

Finally, you can use the Shared modifier (no instance required) and ReadOnly modifier (similar to a constant).

13 years ago, and updated 12 years ago

Code

Article
Nothing New Since Your Last Visit
12847
Hits

VB.Net Language

Mike Prestwood
11. VB.Net Member Method (Sub, Function)

VB.Net uses the keywords sub and function. A sub does not return a value and a function does. Many programmers like to use the optional call keyword when calling a sub to indicate the call is to a procedure.

13 years ago, and updated 12 years ago

Code
Nothing New Since Your Last Visit
8280
Hits

VB.Net Language

Mike Prestwood
12. VB.Net Member Modifiers

The method modifiers include MustOverride, NotOverridable, Overridable, Overrides. Specify VB.Net member modifiers as follows:

Public Overrides Function SomeFunction() As Double

The field modifiers include ReadOnly and Shared. Specify field modifiers as follows:

Public ReadOnly SomeField As String

12 years ago
(1 Comments , last by Cecelia.M )

Code
Nothing New Since Your Last Visit
9313
Hits

VB.Net Language

Mike Prestwood
13. VB.Net Member Property (property, get, set)

VB.Net uses a special property keyword along with special get and set methods to both get and set the values of properties. For a read-only property, leave out the set method. The value keyword is used to refer to the member field. Properties can make use of any of the access modifiers (private, protected, etc).

My preference for VB.Net code is to start member fields with "F" ("FName" in our example) and drop the "F" with properties that manage member fields ("Name" in our example).

13 years ago, and updated 12 years ago

Code

KB Post
Nothing New Since Your Last Visit
22066
Hits

VB.Net Language

Mike Prestwood
14. VB.Net Overriding (Overridable, Overrides)

In VB.Net, you specify a virtual method with the Overridable keyword in a parent class and extend (or replace) it in a descendant class using the Overrides keyword.

Use the base keyword in the descendant method to execute the code in the parent method, i.e. base.SomeMethod().

12 years ago

Code

Article
Nothing New Since Your Last Visit
27783
Hits

VB.Net Language

Mike Prestwood
15. VB.Net Partial Classes (Partial)

VB.Net supports both partial classes and partial methods.

12 years ago

Code

Article
Nothing New Since Your Last Visit
16379
Hits

VB.Net Language

Mike Prestwood
16. VB.Net Polymorphism

C# supports the following types of polymorphism:

12 years ago

Code
Nothing New Since Your Last Visit
10595
Hits

VB.Net Language

Mike Prestwood
17. VB.Net Prevent Derivation (NotInheritable, NotOverridable)

With VB.Net, use the NotInheritable keyword to prevent a class from being inherited from and use the NotOverridable keyword to prevent a method from being overridden.

A method marked NotOverridable must override an ancestor method. If you mark a class NotInheritable, all members are implicitly not overridable so the NotOverridable keyword is not legal.

13 years ago, and updated 12 years ago

Code
Nothing New Since Your Last Visit
12583
Hits

VB.Net Language

Mike Prestwood
18. VB.Net Self Keyword (Me)

To refer to the current instance of a class or structure, use the Me keyword. Me provides a way to refer to the specific instance in which the code is currently executing. It is particularly useful for passing information about the currently executing instance.

The Me keyword is also used as a modifier of the first parameter of an extension method.

You cannot use Me with static method functions because static methods do not belong to an object instance. If you try, you'll get an error.

12 years ago

Code
Nothing New Since Your Last Visit  
10498
Hits

VB.Net Language

Mike Prestwood
19. VB.Net Shared Members (Shared)

VB.Net supports both static members and static classes (use the keyword Shared). You can add a static method, field, property, or event to an existing class.

You can designate a class as static and the compiler will ensure all methods in that class are static. You can add a constructor to a static class to initialize values.

The CLR automatically loads static classes with the program or namespace.

13 years ago, and updated 12 years ago

Code
Nothing New Since Your Last Visit  
10852
Hits

VB.Net Language

Icon Legend:
Since your last logged visit:
- New to you or updated since your last visit (sign in now to activate).
- NOT new to you since your last visit (sign in now to activate).

New VB.Net Language Knowledge Base Post...

Share your knowledge with the WORLD! In addition to adding comments to existing posts, you can post knowledge you've acquired. We welcome full articles (intro with screen shots), general posts (shorter), and tidbits (tips, FAQs, definitions, etc.).

Post New...

Tidbit Post: Short Flashcard FAQ Definition Quick Tip Code Snippet
Longer Post: Full Article General Post File Link Error News
Other: Blog Topic
Or, if YOU have a question...
  VB.Net Language Message Board
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2021 Prestwood IT Solutions.   [Security & Privacy]