Documente Academic
Documente Profesional
Documente Cultură
OOP I
Agenda
OOP Introduction
Abstraction
Encapsulation
Composition
Inheritance
Polymorphism
Dynamic dispatch
Modularity (general topic)
OOP Introduction
class Car {
float fuelLevel;
byte gear;
float speed;
Color color;
}
Abstraction
class Car {
float fuelLevel; // these are class members
byte gear;
float speed;
Color color;
}
Abstraction
class Person {
String name;
String surname;
byte age;
boolean hungry;
String toString() {
return name + + surname;
}
void eat() {
hungry = false;
}
}
Encapsulation
It is good to:
Be able to have entities which are made of data AND
behavior; they know how to handle their internal state.
Encapsulation
It is good to:
Be able to have entities which are made of data AND
behavior; they know how to handle their internal state.
Be able to hide unwanted details about how a certain class
solves its part of the problem.
Encapsulation
It is good to:
Be able to have entities which are made of data AND
behavior; they know how to handle their internal state.
Be able to hide unwanted details about how a certain class
solves its part of the problem.
The concept which allows both of these is called encapsulation.
It is good to:
Be able to have entities which are made of data AND
behavior; they know how to handle their internal state.
Be able to hide unwanted details about how a certain class
solves its part of the problem.
The concept which allows both of these is called encapsulation.
class Car {
private float fuelLevel;
private byte gear;
private float speed;
private Color color;
}
class Car {
private float fuelLevel;
private byte gear;
private float speed;
private Color color;
Encapsulation in Java is a
mechanism of wrapping the data
(variables) and code acting on the
data (methods) together as as
single unit.
In encapsulation the variables of a
class will be hidden from other
classes, and can be accessed only
through the methods of their
current class, therefore it is also
known as data hiding.
Activity
shape.draw()
shape.draw()
shape.draw()
shape.draw()
Discussion
What are the advantages of OOP?
Homework
Model these entities (book, novel, album) with different classes and
inheritance.
Bibliography
https://docs.oracle.com/javase/tutorial/java/co
ncepts/
Thinking in Java 1. Introduction To Objects
http://beginnersbook.com/2013/04/oops-
concepts/
http://www.tutorialspoint.com/java/java_abstra
ction.htm
http://www.tutorialspoint.com/java/java_encap
sulation.htm
http://www.tutorialspoint.com/java/java_inheri
tance.htm
http://www.tutorialspoint.com/java/java_overri
ding.htm