Object Oriented

To be considered a true object oriented programming language the language must support the following:
Inheritance - Extends the functionality but can't remove it. The ability to derive new classes from existing classes. Allows you to treat objects of a derived type as objects of its base type. This can be used to create specialization.
Polymorphism - Creating routines that can operate an objects of different types that is handled with late binding and multiple interfaces. Allows you to manipulate objects of related types as though they were of a common type.
Encapsulation - Being able to hide parts of the implentation from being seen from the outside. You can use the "private" keyword to prevent variables from being seen from outside the class. The separation between interface and implementation. You can encapsulate the object and it is only made available to the outside through a well defined interface.
Abstraction - This focuses on the interface and gives you the ability to create an abstract representation of an object or concept and therefore being able to hide the complexity and logic. You can use the "private" keyword to prevent methods from being seen from outside the class.


Object Relationships

There are four different ways to think about the relationships between objects.


Inheritance
(is-a relationship)
One object is type of another object
Transfer parent to child


Composition
(part-of relationship)
strong relationship
two objects depend on each other


Association
Relationship between independent or loosely coupled objects.
very weak relationship
two objects are independent


Aggregation
(parent-child relationship)
One object is made up of other objects
This is a special type of one-way association


Inheritance

This is the way derived classes can make use of the functionality in the base class.
This allows you to define a class based on an existing class giving your new class all the behavior and functionality of the existing class.
If classes do not explicitly derive from another class, then they are derived from the Object class.
Derived classes can add or modify the functionality inherited from the base classes


Multiple Inheritance

This is the ability to derive from more than one class
In VB classes can only derive from one class and therefore does not support multiple inheritance.
In VB however classes can implement multiple interfaces
The ability to implement multiple interfaces accomplishes much the same thing.
Infact some object oriented programmers might argue that multiple interfaces is superior to multiple classes because it provides the equivalent capability but with less confusion.
A derived class can only have one base class ?


Inheriting Base Class Members

When a derived class inherits from a base class it inherits everything
If you want to change the behaviour of the base class you have two options:
1) Replacing the base class member (new). Also known as hiding or shadowing.
2) Extending the base class member (virtual + override).


Base Class Members - Replacing

The "new" modifier hides (and replaces) a member from the base class with a new one
Use the new modifier to explicitley hide a member inherited from a base class which has the same name
Try and avoid using method hiding where possible as it leads to a lot of confusion.
When you don't want to override an existing method just use a different name.

class Base 
{
    public void Method1()
    {
        System.Console.WriteLine("Base - Method1");
    }
}

class Derived : Base
{
    // public void Method1
    // new public void Method1
    public new void Method1()
    {
        System.Console.WriteLine("Derived - Method1");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Base B = New Derived()
        B.Method1(); //Base - Method1
    }
}

The compile-time type is Base
The run-time type is Derived
For non-virtual methods the compile-time type is used.


Base Class Members - Extending

Derived classes can define override methods that can extend the base class method.


class Base 
{
    public virtual void Method2()
    {
        System.Console.WriteLine("Base - Method2");
    }
}

class Derived : Base
{
    public override void Method2()
    {
        System.Console.WriteLine("Derived - Method2");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Base B = New Derived()
        B.Method2(); //Derived - Method2
}

The compile-time type is Base
The run-time type is Derived
For virtual methods the run-time type is used.


Inherits - VB.Net

Makes a class gain all the behaviour of another class, so you don't have to implement them yourself.


Important

Unlike Java methods are not virtual by default.


Polymorphism

Objects of a derived class can be treated as an object from the base class.
Is the ability to create identically named members within a number of derived class that can different functionality.
This can be achieved either by using Inheritance or by implementing an interface differently in different classes.


An object of the derived class may be referred to (or cast) as either being a base class type.


To understand polymorphism you need to understand the following
1) inheritance
2) virtual methods - A virtual method can be overridden in an inherited class by using the same name and signature
3) late binding - the method being called is looked up by name at runtime


There are two types of polymorphism


Static or Compile Time Polymorphism

The decision is made at compile time
Method overloading uses this type of polymorphism
and is implemented by more than one method with the same name but different parameters



Dynamic or Run Time Polymorphism

The decision is made at run time
Method overriding uses this type of polymorphism
and allows us to have methods in the base class and the derived class with the same name and same parameters


Encapsulation


Enables you to control the access to data within a class
Not allowing direct access to certain methods and hiding the logic used in the class.


You can hide the implementation of a class by using access modifies that prevent code outside the class from modifying data within the class or calling its methods.



Access Modifiers

You declare a class using the Class Keyword

[attributes][access-modifier]Class identifier 
[inherits classname]
   {class body}
End Class

Keeping each type or class discreet and self contained.
Each class should be fully encapsulated, that is, it should define the state and responsibilities of that type.
For example, if you create an Employee object, that Employee object should fully define all there is to know about each Employee.
This allows you to change the implementation of one class without affecting any other classes.
This is achieved by making a clear distinction between the public interface of the class and its private implementation
A client can rely on a public interface not to be changed.


Abstraction



Composition

In general terms, composition allows a class to contain an object instance of another class.
Composition can be denoted as being an "as a part" or a "has a" relationship between classes.
In the composition approach, the derived class becomes the front-end class and the base class becomes the back-end class.
The composition approach provides stronger encapsulation than inheritance, because a change to a back-end class does not necessarily break any code that relies on the front-end class.
The main advantages of composition is, with carefully designed interfaces we can change references of back end classes at runtime.


Think of inheritance when there is a relationship between two things.

A car "is a" vehicle, a person "is a" mammal 

Think of composition when there something has a relationship with something else.

A car "has an" engine, a person "has a" name 

Inheritance vs Composition

In inheritance, there is an image of the base class in the derived class object, so the image of the base class is created when the derived class object is created.
Composition allows late creation of the backend class object until and unless they are not really required.


In inheritance the base class remains a part of the derived class object throughout the life of the derived class.
In composition, life of the backend class is independent and we can change back end object dynamically.


Inheritance is static binding (compile time binding)
Composition is dynamic binding (run time binding)


Inheritance comes with polymorphism.
Composition has no concept of polymorphism


In inheritance, there is a single invocation of an inherited base class so there is no extra cost for invocation.
In composition the explicit method invocation (forwarding or delegation) has a performance cost (note that performance depends on many factors).


In inheritance a change in the base class interface cannot ripple down the inheritance hierarchy to a derived class.
In composition it is easy to change the interface of a back-end class and front-end class


In inheritance it is not required to implement all base class methods within the derived class.
In composition, all methods provided by composed classes must be implemented in the front end class.


In inheritance the derived class and base class interfaces are tightly coupled.
In composition the front-end and back-end interfaces are loosely coupled.


It is easier to add new derived classes in inheritance than to add new front-end class in composition.



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext