OOPS Concepts – Objects


What is Object?

Objects are the basic run-time entities in an object-oriented system. Object is concept of Object Oriented Programming (OOPS). Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data. An Object is a collection of data members and associated member functions also known as methods. An object is an instance of a class. A class must be instantiated into an object before it can be used in the software. More than one instance of the same class can be in existence at any one time. For example whenever a class name is created according to the class an object should be created without creating object can’t able to use class.

Consider the following class structure :

Class Name : Employee

''' <summary>
''' Simple Employee Class for Dot Net Programming.
''' </summary>
''' <remarks></remarks>
Public Class Employee
    'Class definition goes here i.e. Variables, Methods, Properties, and Functions.
End Class  

Private variables : EmployeeId, EmployeeName, EmployeeAddress.

'Private Variables
Private EmployeeCode As Integer
Private EmployeeName As String
Private EmployeeAddress As String
Private EmployeeContact As Long  

Properties : ID, Name, Address, Contact.

''' <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

Methods : Add, Modify, Delete

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  

Now you can create multiple Objects of this class as shown below

Dim EmployeeObject1 As Employee = New Employee
Dim EmployeeObject2 As Employee = New Employee
Dim EmployeeObject3 As Employee = New Employee  
Advertisements

2 comments

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