Object Oriented Programming Chapter 1: Introduction to OOP Prepared by: Mahmoud Rafeek Alfarra 2016
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
Lecture Let’s think on concept of Class and Object 2
(‫ى‬َ‫م‬ْ‫ع‬َ‫أ‬ ِ‫ة‬َ‫م‬‫ا‬َ‫ي‬ِ‫ق‬ْ‫ل‬‫ا‬ َ‫م‬ْ‫و‬َ‫ي‬ ُ‫ه‬ُ‫ر‬ُ‫ش‬ْ‫ح‬َ‫ن‬َ‫و‬ ‫ًا‬‫ك‬‫ن‬َ‫ض‬ ً‫ة‬َ‫ش‬‫ي‬ِ‫ع‬َ‫م‬ ُ‫ه‬َ‫ل‬ ََّ‫ن‬ِ‫إ‬َ‫ف‬ ‫ي‬ِ‫ر‬ْ‫ك‬ِ‫ذ‬ ْ‫ن‬َ‫ع‬ َ‫ض‬َ‫ر‬ْ‫ع‬َ‫أ‬ ْ‫ن‬َ‫م‬َ‫و‬) ‫ه‬‫ط‬ ‫ة‬‫ر‬‫و‬‫س‬
Classes & Objects !
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
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
Class & Object
Class & Object
Class & Object
Class & Object
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.
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 …
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
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 constructor which gives initial values to the attributes of class Is a reserved word The identifier of class Must be as any variable
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
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
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
Practices Group 1 Compare between constructor and methods in class. Group 2 Detect 3 classes from your bedroom and 2 objects. Group 3 Diffrenciate between Class & Object Group 4 Draw the UML Class Diagram of Course class. Group 5 Draw the UML Class Diagram of Student class. Group 6 Thinking to build Circle class.
THANKS! Any questions? You can find me at: Fb/mahmoudRAlfarra Staff.cst.ps/mfarra Youtube.com/mralfarra1 @mralfarra

Object Oriented Programming_Lecture 2

  • 1.
    Object Oriented Programming Chapter1: Introduction to OOP Prepared by: Mahmoud Rafeek Alfarra 2016
  • 2.
    Outlines ◉ What isObject-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
  • 3.
    Lecture Let’s think onconcept of Class and Object 2
  • 4.
    (‫ى‬َ‫م‬ْ‫ع‬َ‫أ‬ ِ‫ة‬َ‫م‬‫ا‬َ‫ي‬ِ‫ق‬ْ‫ل‬‫ا‬ َ‫م‬ْ‫و‬َ‫ي‬ُ‫ه‬ُ‫ر‬ُ‫ش‬ْ‫ح‬َ‫ن‬َ‫و‬ ‫ًا‬‫ك‬‫ن‬َ‫ض‬ ً‫ة‬َ‫ش‬‫ي‬ِ‫ع‬َ‫م‬ ُ‫ه‬َ‫ل‬ ََّ‫ن‬ِ‫إ‬َ‫ف‬ ‫ي‬ِ‫ر‬ْ‫ك‬ِ‫ذ‬ ْ‫ن‬َ‫ع‬ َ‫ض‬َ‫ر‬ْ‫ع‬َ‫أ‬ ْ‫ن‬َ‫م‬َ‫و‬) ‫ه‬‫ط‬ ‫ة‬‫ر‬‫و‬‫س‬
  • 5.
  • 6.
    o Classes areconstructs 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
  • 7.
    o “Object” isan 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
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
    Thinking to buildclass … 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.
  • 13.
    o A Javaclass 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 …
  • 14.
    Thinking to buildclass … 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
  • 15.
    How to buildmy class? Access_modifiers class class_name { // variables = attributes Access_modifiers class_name(par1, par2, …) { } // behavior = methods } Always, the class has a method called constructor which gives initial values to the attributes of class Is a reserved word The identifier of class Must be as any variable
  • 16.
    o A classcan 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
  • 17.
    How to insatiateobject? 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
  • 18.
    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
  • 19.
    Practices Group 1 Compare between constructorand methods in class. Group 2 Detect 3 classes from your bedroom and 2 objects. Group 3 Diffrenciate between Class & Object Group 4 Draw the UML Class Diagram of Course class. Group 5 Draw the UML Class Diagram of Student class. Group 6 Thinking to build Circle class.
  • 20.
    THANKS! Any questions? You canfind me at: Fb/mahmoudRAlfarra Staff.cst.ps/mfarra Youtube.com/mralfarra1 @mralfarra