You are on page 1of 11

Cloud Computing Labs

Lab 2: Object Oriented Programming In


Java

Lecturers : Muthanna Jabbar, Ali Munther


Lab 2
Fourth Class .
Sun 16/11/2022
(Department: Informatics Systems Management (ISM
2022
1
1.
Outline
Fundamentals of Object Oriented Programming
 The concept of object oriented programming was not invented suddenly
buy it came through a sequence of continuous connected steps:
1. Modular programming. 2. Top – down programming.
3. Bottom – up programming. 4. Structure programming.
 The main reason that the developers invented the previous techniques
is because the programs complexity grow through the time depending
on the need of the software markets, to achieves two goals:
1. Reliability. 2. Maintainability.
 According to the above goals the C-language was developed and rolled
the software world during the 80's and it was designed a ( structured
programming language), but also due to the growth of the programs the
developers reached the point that the programs was not:
1. Bugs free. 2. Easy to maintain. 3. Reusable.
 Therefor the developers designed a totally new concept of programming
in which they merged the best of structured programming and other
new features and concept, and this new way of programming and
developing programs is called (Object Oriented Programming).
 JAVA is a pure object oriented programming language.
2
Outline
1.1 Object Oriented Paradigm
 Object oriented programming (OOP)is
designed to element the some of failure
of procedural programming.
 The OOP treats (Data) as critical
element in the program, does not allow
it to flow freely around the system.
 The OOP allows the developers
(programmers) to decompose a problem
into a number of entities called
 Object = Data + Methods.
(Objects). This technique is similar to
 According to the above
the technique of (Divide and Conquer).
figure, it's clearly that (Data)
 Since OOP deals with (Objects), then we
of one object can be accessed
need (Data), and (Functions) to be build
by its methods only.
around these objects. Functions in
 But the method of an object
JAVA are called (Methods).
can be accessed by methods
 According to the above, there IS_A a
of another objects.
direct relation between the objects on
one side and the (data, methods).
3
Outline
1.2 Basics concepts of OOP
 The object oriented programming characteristics which is implemented
by the JAVA programming language is as follows:
a. Objects and Classes:
 objects are the basic runtime entities in an Object Oriented
system.
 The objects should be chosen such that they match closely with
real world objects.
 When a program is executed, the objects interact by sending
massages to one another.
 Example: Suppose we have 2 –objects (1. Customer 2. Account), in
banking program. If the(customer) object send a massage to the
(account) object requesting for balance, then each object contains
(data) and (code) to manipulate the (data), but these objects
interact without the need to know each other (data) or (code).
 From the above example it's clear that it's so sufficient for these
two objects to know only the type of massage accepted and the
type of response returned by the objects.

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

You might also like