You are on page 1of 19

OOPs

it’s Java…
An Introduction to Object-oriented
Programming using Java

Copyright 2018 Aimee Theresa A. Fontanilla


Outline

Introduction to Classes
•Properties (all public)
•Methods (all public)
•Class Diagram

Copyright 2018 Aimee Theresa A. Fontanilla


Objectives

• Differentiate structured programming from


object-oriented programming.
• Identify the features of object-oriented language
and explain how they contribute towards
facilitating the software development process.
• Identify the Java construct for supporting
inheritance, polymorphism, encapsulation and
abstraction.

Copyright 2018 Aimee Theresa A. Fontanilla


Kinds of Programming

•Programming paradigms (some samples)


• Structured programming – C, Pascal, Fortran
• Object-oriented programming – C++, Java
• Logic programming - Prolog
• Functional programming- Scheme, Haskell

Copyright 2018 Aimee Theresa A. Fontanilla


Pascal
program mine(output);
var i : integer;
procedure print(var j: integer);
function next(k: integer): integer;
begin
next := k + 1
end;
begin
writeln('The total is: ', j);
j := next(j)
end;
begin
i := 1;
while i <= 10 do
print(i)
end.
Copyright 2018 Aimee Theresa A. Fontanilla
C++

#include <iostream>
// provides std::cout
int main()
{
std::cout << "Hello, world!\n";
}

Copyright 2018 Aimee Theresa A. Fontanilla


Prolog

sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).


parent_child(X, Y) :- father_child(X, Y). parent_child(X, Y) :-
mother_child(X, Y). mother_child(trude, sally).
father_child(tom, sally). father_child(tom, erica).
father_child(mike, tom).

Copyright 2018 Aimee Theresa A. Fontanilla


Scheme

(define (fact n)
(if (= n 0)
1
(* n (fact (- n 1)))))

Copyright 2018 Aimee Theresa A. Fontanilla


Structured
programming EXIT POINT

ENTRY POINT

Copyright 2018 Aimee Theresa A. Fontanilla


Structured Programming

• one entry and exit point and step-by-step program


execution.
• allows sequence, decision (conditions and selections) and
loop constructs
• compartmentalization of code and data - ability to section
off and hide from the rest of the program all the information
and instruction necessary to perform a specific task.
• subroutines or modules (methods).
• makes use of global and local variables

Copyright 2018 Aimee Theresa A. Fontanilla


Object-oriented Programming (OOP)
modeling the properties and behavior of real
objects in the software.
In a car factory:
blueprint (Class) (Herbie) Object

Properties or State
# of liters of gas in tank
total # of km run so far
efficiency (km/liter)
Behavior
drive
load gas
change efficiency
check gas
check odometer reading

Classes contain members, the fields (or data) and the


methods that operate on the fields.
Copyright 2018 Aimee Theresa A. Fontanilla
Member fields

• Member fields specify the data types defined in the class


• The design of a class begins by identifying the properties
that are relevant to the objective of the system.

Properties or State Data/Field/Variable


# of liters of gas in tank-------------NumOfLiters
total # of km run so far-------------TotalKmRun
efficiency (km/liter)-----------------Efficiency

Copyright 2018 Aimee Theresa A. Fontanilla


Member methods

Member methods specify the operations on the member


fields
The method to be supported is influenced by the member
fields of the class.

Behavior Method
Drive-------------------------------- drive ()
load gas ---------------------------- loadGas(NumOfLiter)
change efficiency-----------------changeEfficiency()
check gas---------------------------checkGas(NumOfLiter)
check odometer reading -------checkOdometer()

Copyright 2018 Aimee Theresa A. Fontanilla


Basic OOP design concepts

•Abstraction
•Encapsulation
•Inheritance
•Polymorphism

Copyright 2018 Aimee Theresa A. Fontanilla


Abstraction

• hiding of non-essential details in a model and providing


only the mechanism for specifying those that are relevant
to the objective.
• Object-oriented Java promotes abstraction by allowing
classes to be used without the need to understand its
internal mechanism.

Copyright 2018 Aimee Theresa A. Fontanilla


Encapsulation
• Encapsulation refers to the packaging of the class
definition in such a way that only those methods
and properties intended to interface with other
objects will be exposed, while the rest will be
inaccessible to the rest of the program.

hour, minute, second


Move second hand
Move minute hand
Move hour hand

Copyright 2018 Aimee Theresa A. Fontanilla


Inheritance

• Inheritance provides
the mechanism that
enables a program to
acquire and extend the
properties and
behavior of an existing
software.

Copyright 2018 Aimee Theresa A. Fontanilla


Polymorphism

• Polymorphism
provides the
mechanism that
enables child
classes to modify an
existing behavior of
the parent class.

Copyright 2018 Aimee Theresa A. Fontanilla


Mata ne…

Copyright 2018 Aimee Theresa A. Fontanilla

You might also like