Professional Documents
Culture Documents
Object Oriented Programming: Main Concepts of OOP
Object Oriented Programming: Main Concepts of OOP
O Chapter 1
P
2012
1 What is OOP?
2 Procedural VS OO
3 Main Concepts
5 Access modifiers
6 Access methods
http://mfarra.cst.ps
O
O
O
O
PP
What is OOP?
http://mfarra.cst.ps
O
O
O
O
PP
Procedural VS OO
http://mfarra.cst.ps
O
O
O
O
PP
Procedural VS OO
http://mfarra.cst.ps
O
O
O
O
PP
Main Concepts
OOP
http://mfarra.cst.ps
O
O
O
O
PP
Abstraction
http://mfarra.cst.ps
O
O
O
O
PP
Encapsulation
http://mfarra.cst.ps
O
O
O
O
PP
Inheritance
Inheritance: is a form of software reuse in
which a new class is created by absorbing
an existing class's members and
embellishing them with new or modified
capabilities.
http://mfarra.cst.ps
O
O
O
O
PP
Polymorphism
http://mfarra.cst.ps
O
O
O
O
PP
Diagram of program structure
Program
Methods Variables
A program
Statements
consists of one or
more classes.
Typically, each
class is in a
separate .java file.
http://mfarra.cst.ps
O
O
O
O
PP
Class & Object
http://mfarra.cst.ps
O
O
O
O
PP
Class & Object
http://mfarra.cst.ps
O
O
O
O
PP
Class & Object
http://mfarra.cst.ps
O
O
O
O
PP
Thinking to build class …
Each
Eachone
oneisispresented
presentedas as
aavariable
variableininthe
theClass
Class Attributes
Any Thing
Each
Eachone
oneisispresented
presentedasas
aamethod
methodininthe
theClass
Class Behavior
http://mfarra.cst.ps
O
O
O
O
PP
How to build my class?
Is a reserved word
Access_modifiers
Access_modifiersclass
classclass_name
class_name{{
//
//variables
variables==attributes
attributes
Access_modifiers
Access_modifiersclass_name()
class_name(){{
}}
//
//behavior
behavior==methods
methods Always, the class has
a method called constructor
}} which gives initial values
to the attributes of class
http://mfarra.cst.ps
O
O
O
O
PP
My first class …
class Rectangle {
public float length;
public float width; Attributes(properties, instance variables)
of rectangle class
public float area;
public Rectangle(){
length = 1.0f;
Default Constructor of class
width = 1.0f; It just gives any values to properties
area = recArea();
}
http://mfarra.cst.ps
O
O
O
O
PP
Access modifiers
http://mfarra.cst.ps
O
O
O
O
PP
Access modifiers
4 Access Modifiers:
package.
http://mfarra.cst.ps
O
O
O
O
PP
Access modifiers
4 Access Modifiers:
http://mfarra.cst.ps
O
O
O
O
PP
Access modifiers
4 Access Modifiers:
http://mfarra.cst.ps
O
O
O
O
PP
Access modifiers
http://mfarra.cst.ps
O
O
O
O
PP
Access methods
setData getData
public void setData(data){ public data getData(){
This.data.data; return data;
} }
http://mfarra.cst.ps
O
O
O
O
PP
Access methods
class Rectangle {
private float length;
private float width;
private float area;
public Rectangle(){
length = 1.0f;
width = 1.0f;
area = recArea(); }
public Rectangle(float l, float w){
length = l;
width = w;
area = recArea(); }
public float recArea(){
return length*width; }
public void setLenghth(float length){
this.length = length;
}
public float getLength(){
return length;
}
} http://mfarra.cst.ps
O
O
O
O
PP
استغفروا ربكم
ن ال ّل هُوما كا َ َ}
ت ِفي ِه مْ
م َوأ ْن َ ِل ُي عَ ّذ َب ُه ْ
ن ال ّل ُه َوما كا َ
ه مْ م َو ُ ُم عَ ّذ َب ُه ْ
ن{
غ ِف ُرو َ س َت َْي ْ
http://mfarra.cst.ps
O
O
O
O
PP
Thank You …
QUESTIONS?
http://mfarra.cst.ps