OOPS Concepts – Class


What is Class?

In Object-Oriented Programming, a class is an extensible template for creating objects, providing initial values for state (Member Variables) and implementations of behavior (Member Functions, Methods). In many languages, the class name is used as the name for the class (the template itself), the name for the default constructor of the class (Subroutine that creates objects), and as the type of objects generated by the type, and these distinct concepts are easily conflated.

When an object is created by a constructor of the class, the resulting object is called an “Instance” of the class, and the member variables specific to the object are called “Instance Variables”, to contrast with the class variables shared across the class.

  • A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass.
  • Subclasses can also define their own methods and variables that are not part of their superclass.
  • The structure of a class and its subclasses is called the class hierarchy.

Consider the following class Employee :

 ''' <summary>
''' Simple Employee Class for Dot Net Programming.
''' </summary>
''' <remarks></remarks>
Public Class Employee
    'Private Variables
    Private EmployeeCode As Integer
    Private EmployeeName As String
    Private EmployeeAddress As String
    Private EmployeeContact As Long
    ''' <summary>
    ''' Gets or sets Employee ID.
    ''' </summary>
    ''' <value>Employee Id As Integer</value>
    Public Property ID As Integer
        Get
            Return Me.EmployeeCode
        End Get
        Set(value As Integer)
            Me.EmployeeCode = value
        End Set
    End Property
    ''' <summary>
    ''' Gets or sets Employee Name.
    ''' </summary>
    ''' <value>Employee Name As String</value>
    Public Property Name As String
        Get
            Return Me.EmployeeName
        End Get
        Set(value As String)
            Me.EmployeeName = value
        End Set
    End Property
    ''' <summary>
    ''' Gets or sets Employee Address.
    ''' </summary>
    ''' <value>Employee Address As String</value>
    Public Property Address As String
        Get
            Return Me.EmployeeAddress
        End Get
        Set(value As String)
            Me.EmployeeAddress = value
        End Set
    End Property
    ''' <summary>
    ''' Gets or sets Employee Contact.
    ''' </summary>
    ''' <value>Employee Contact As Long</value>
    Public Property Contact As Long
        Get
            Return Me.EmployeeContact
        End Get
        Set(value As Long)
            Me.EmployeeContact = value
        End Set
    End Property

    Public Sub Add()
        'Write your Add Logic here.
    End Sub

    Public Sub Modify()
        'Add your Modify Logic here.
    End Sub

    Public Sub Delete()
        'Add your Delete Logic here.
    End Sub

End Class 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s