object oriented programming_lecture 2
TRANSCRIPT
![Page 1: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/1.jpg)
Object Oriented Programming
Chapter 1: Introduction to OOP
Prepared by: Mahmoud Rafeek Alfarra
2016
![Page 2: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/2.jpg)
Outlines◉What is Object-Oriented Programming ?
◉Procedural vs. Object-Oriented Programming
◉OO Programming Concepts
◉Concept of Objects and classes
◉UML Class Diagram
◉Visibility Modifiers and Accessor Methods
◉Full Example
![Page 3: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/3.jpg)
Lecture Let’s think on concept of Class and Object
2
![Page 4: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/4.jpg)
ومن أعرض عن ذكري )فإن له معيشة ضنكا ونحشره يوم القيامة
(أعمىسورة طه
![Page 5: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/5.jpg)
Classes & Objects !
![Page 6: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/6.jpg)
o Classes are constructs that define objects of the same type.
o “Class” refers to a blueprint. It defines the variables and methods the objects support.
What is Class ?
Class Name: Circle Data Fields:
radius is _______ Methods:
getArea
A class template
![Page 7: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/7.jpg)
o “Object” is an instance of a class.o Each object has a class which defines its data and behavior.o An object has both a state and behavior. o The state defines the object, and the behavior defines what
the object does.
What is Object?
Class Name: Circle Data Fields:
radius is _______ Methods:
getArea
Circle Object 1 Data Fields:
radius is 10
Circle Object 2 Data Fields:
radius is 25
Circle Object 3 Data Fields:
radius is 125
A class template
Three objects of the Circle class
![Page 8: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/8.jpg)
Class & Object
![Page 9: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/9.jpg)
Class & Object
![Page 10: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/10.jpg)
Class & Object
![Page 11: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/11.jpg)
Class & Object
![Page 12: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/12.jpg)
Thinking to build class …
Any Thing
Attributes
Behavior
Each one is presented as a variable in the Class
Each one is presented as a method in the Class
A new class will be considered as a new data type, so you can declare a variables (Objects) of them and then you can set and get data to its properties.
![Page 13: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/13.jpg)
o A Java class uses variables to define data fields and methods to define behaviors.
o Additionally, a class provides a special type of methods, known as constructors, which are invoked to construct objects from the class.
Thinking to build class …
![Page 14: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/14.jpg)
Thinking to build class … class Circle {
/** The radius of this circle */ double radius = 1.0; /** Construct a circle object */ Circle() { } /** Construct a circle object */ Circle(double newRadius) { radius = newRadius; } /** Return the area of this circle */ double getArea() { return radius * radius * 3.14159; }
}
Data field
Method
Constructors
![Page 15: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/15.jpg)
How to build my class?
Access_modifiers class class_name {// variables = attributes Access_modifiers class_name(par1, par2, …) {
}// behavior = methods
}
Always, the class has a method called constructorwhich gives initial values to the attributes of class
Is a reserved word The identifier of class Must be as any variable
![Page 16: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/16.jpg)
o A class can have three kinds of members: fields: data variables which determine the status of the
class or an object methods: executable code of the class built from
statements. It allows us to manipulate/change the status of an object or access the value of the data member
nested classes and nested interfaces
Class Members
![Page 17: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/17.jpg)
How to insatiate object?
class_name object_name = new class_name (arg1, arg2, …);
The name of class, which you want to insatiate an object of it.
Reserved word
Values based on the parameters of constructor
The name of object
![Page 18: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/18.jpg)
UML Class Diagram
Circle radius: double Circle() Circle(newRadius: double) getArea(): double
circle1: Circle radius = 1.0
Class name Data fields Constructors and methods
circle2: Circle radius = 25
circle3: Circle radius = 125
UML Class Diagram
UML notation for objects
![Page 19: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/19.jpg)
PracticesGroup 1Compare between constructor and methods in class.
Group 2Detect 3 classes from your bedroom and 2 objects.
Group 3Diffrenciate between Class & Object
Group 4Draw the UML Class Diagram of Course class.
Group 5Draw the UML Class Diagram of Student class.
Group 6Thinking to build Circle class.
![Page 20: Object Oriented Programming_Lecture 2](https://reader036.vdocuments.us/reader036/viewer/2022081521/587ad7a11a28ab542b8b47f1/html5/thumbnails/20.jpg)
THANKS!
Any questions?You can find me at:
Fb/mahmoudRAlfarraStaff.cst.ps/mfarraYoutube.com/mralfarra1@mralfarra