In a real world, it is refer as object itself with the related class and instance terms that defined the major functionality such as Abstraction, Encapsulation, Polymorphism, and Inheritance concepts necessary for a language to be completely object oriented. This four major functionality has their own advantages in different programming languages for their various field of specialization. To accomplish, they must be familiar with the following tasks.
Abstraction – The capability of a language to make “Black Box” code, to obtain a computer and create an abstract representation of that perception contained by the program. It captures merely those details regarding an object that are important to the existing perception.
Encapsulation – This concepts of a severance among interface and implementation and enables you to cover up the internal implementation details of a class. A language mechanism for restricting access to some of the object’s component. Typically, only the object's own methods can directly inspect or manipulate its fields.
Interface – defined as a set of methods; public, properties, fields, and events in a class and as long it remains consistent that can intent with your objects.
Ex. 1
Public Function GetValue() As String
End Function
This method is declared with the public keyword; it is part of the interface and can be called by client application that using application.
Ex. 2
Private Sub MyMethod()
End Sub
This method declared as private, it’s not considered as part of the interface, rather can only be called by code within the class not by any code outside the class.
Ex. 3
Public Sub calculate()
MyMethod()
End Sub
In this case, you’re calling the private method for within a public method.
Implementation or Behavior – it is a set of statements that do something inside the method. This usually involves the following: changing its own state and somehow affecting the world outside the object.
Ex. 1
Private Age As Integer
Public ReadOnly Property age() As Integer
Get
Return Age
End Get
End Property
The code above returning a value directly out of a variable. The key point is to understand that client application can use the object even if you change the implementation, as long as you do not change the interface.
Note: Keep in mind the encapsulation is a syntactical tool that enables the code to continue running without changes. However, it is not semantic, meaning that just because the code enable to continue to run, that does not mean it continue to do what you actually want it to do.
Polymorphism – It is the ability to write one routine that can operate an object from more than one class, treating different object from different classes. For instance, it is reflected if both customer and vendors object have name property regardless of whether you are using customer or vendor’s objects.
Inheritance – Is used to create object that have everything another object has, the idea that a class can gain the interface and behavior of a preexisting class. One thing that you need to understand about inheritance is the way that access to public and private members is controlled.
The final major techniques you need to understand are inheritance and the use of multiple instances.
The inherits keyword to make Employee a subclass of Person, add a single line of code
Public Class Employee
Inherits Person
End Class
It indicates that a class should derive from an existing class, inheriting the interface and behavior from that class. So, any properties, fields, etc. from Person is inherits from Employee.
Maybe the hardest aspects of Object – Oriented Programming is to understand how to divide up the accountability for the work. One of the majority advantages aspects of object orientation is code reuse, because every time the methods needed in the certain objects just merely call the method needed correspond to the requirements specification.
Next: Object, classes, and Instances
Next: Object, classes, and Instances
0 comments:
Post a Comment