Professional Documents
Culture Documents
4
Outline
1.2 Basics concepts of OOP (continue….)
representing of an object:
Put in mind that the (methods) are the sections in the objects that will
contains the code that will manipulate the data (data) of the objects.
As it is mentioned early, objects contains (data) and (methods), the
entire set of (data) and (methods) is put together in a (class).
A (class) can be thought as a (data type) and an (object) as a variable
of that data type.
Therefore once we create a (class), we can create any number of
(objects) belonging to that (class).
It is clear that each object is associated with the data of type class
with which they are created. Thus a class is a collection of objects of
similar type. Class is a user defined data type and behave like they
built- in. 5
Outline
2 Data Encapsulation and data Abstraction
The [ Wrapping ] of [Data] and [Methods] into a single unit called [Class] ,
is called [Encapsulation].
The [Encapsulation] technique is the most important features of
[Classes].
Using {Encapsulation] will protect the [Data] inside the [Class] from
being accessed from the outer world.
The [Data] are accessible from only the [Methods] which are [Wrapped] in
the same [Class], by providing [Interface] between [Objects data] and the
main program. This will protect the data from direct access by the
program, that is called [Data hiding].
The [Encapsulation] makes it possible for objects to be treated like [Black
Box], as shown below:
6
Outline
2 Data Encapsulation and data Abstraction
[Abstraction], is the art of representing essential features without the
including the background details or explanation.
[Class], applies this concept [Abstraction] and are defined as a list of
abstract attributes.
Example of Encapsulation:
If we consider the following data [ size, width, and cost] as the
data to be manipulated by number of methods that operate on
these data, then all these essential properties of the objects will
be encapsulated in these objects that will be created.
Example of Abstraction:
Any type of mobile of any type of manufactures will be including a
number of some features such as:
1. Sending and receiving text massages.
2. Dialing a call.
3. Receiving a call, and so on.
In the end Encapsulation will offer a result of any action to the
final (end user) without the need to make user a part of the
process.
7
3 Inheritance Outline
[Inheritance], is the process by which objects of one class acquire the
properties of objects of another class, Support the concept of
[Hierarchical classification].
[Inheritance] will provides the capability of [Reusability], this means
we can use a method of a class in another class without modifying the
original method.
The new [Sub class], is almost, but not exactly the same the main
class. The [Sub class], can define only the features that are unique to
it, because the [Sub class] will contain mainly the inherited items
from the main class [Super class].
8
4 Polymorphism Outline
The above term means the ability to take more than one form.
In another word, is the ability of an [Object] to take on many forms.
The most common use of {Polymorphism] in "OOP" accurse when a [Parent
Class] refers to a [Child Class] object.
Example:
From the above figure it's clear that [Polymorphism] play's an important
role in allowing "Objects" having different internal structure to share the
same external interface.
[Polymorphism] is the extensively used in implementing [Inheritance].
9
Outline… )
4 Polymorphism(continue
Example:
Public interface Vegetarian{};
Public class Animal{}
Public class Deer extends Animal implements Vegetarian{}
Explanation :
1. The [class Deer] is considered to be [Polymorphism], since this has
multiple [Inheritance] as shown below:
1.1 A "Deer" is a "Animal".
1.2 A "Deer" is a "Vegetarian".
1.3 A "Deer" is a "Deer".
1.4 A "Deer' is a "Object".
2. Now when we apply the reference variable f to "Deer" object
reference, the following declaration is true:
2.1 Deer d = new Deer();
2.2 Animal a = d;
2.3 Vegetarian v = d;
2.4 Object o = d;
It's clear from above all the reference variables (d, a,v,o) refer to the
same Deer object in the heap.
10
THANK YOU
11