01 OOP - Lecture#1
01 OOP - Lecture#1
6 من1 الصفحة
In object-oriented programming (OOP), an application consists of a
number of objects that ask services from each other.
OO programming is the most popular programming paradigm currently
in use. Some examples of object-oriented programming languages are
Eiffel, Smalltalk, C++, and Java.
6 من2 الصفحة
An object is an instance of a class. You can create many instances of a
class.
Creating an instance is referred to as instantiation.
The terms object and instance are often interchangeable.
6 من3 الصفحة
In other words, we will have circles of different sizes based on the
current value of each radius.
o To define the behavior of circle objects, you may define
operations named getArea () and getPerimeter (). These
operations can be invoked on the circle object but not on the
circle class.
o Another example is the rectangle class. In this case, the variables
width and height are used to characterize any rectangle and
they together represent the state of any rectangle. The current
values of the width and height represent different objects of the
class rectangle. In other words, we will have rectangles of different
sizes (dimensions) based on the current value of each width and
height for each rectangle.
o To define the behavior of rectangle objects, you may define
operations named getArea () and getPerimeter (). These
operations can be invoked on the rectangle object but not on the
rectangle class.
6 من4 الصفحة
What we are concerned about is the “abstract” view of these operations
that will help us to drive the car forward and reach our destination. This
is a simple example of abstraction.
Abstraction reduces the programming efforts and thereby the
complexity. An end-user using the application need not be concerned
about how a particular feature is implemented. He/she can just use the
features as required.
The encapsulation
Encapsulation refers to combining data and associated functions as a
single unit (the class).
Encapsulation is the technique whereby the object's state is hidden from
the outer world and a set of public methods for accessing this state are
exposed.
When each object keeps its state private inside a class, we can say that
encapsulation was achieved. This is why encapsulation is also referenced
as the information hiding mechanism.
Encapsulation is all about implementation. Its main purpose is to hide
the internal working of objects from the outside world so that you
can change it later without impacting outside clients.
6 من5 الصفحة
Modifiability: it is easy to make minor changes in the data
representation or the procedures in an OO program. Changes inside a
class do not affect any other part of a program, since the only public
interface that the external world has to a class is through the use of
methods (functions). This is due to the information hiding principle.
Extensibility: adding new features can be solved by introducing a
few new objects and modifying some existing ones;
Maintainability: objects can be maintained separately, making
locating and fixing problems easier.
Re-usability: objects can be reused in different programs.
6 من6 الصفحة