Object Oriented Programming
Dr. Mohammad Abdeen
Spring 2020/2021
Overview of the course
• Instructors
– Lectures: Dr. Mohammad Abdeen
– Labs: Mr. Omar Namnakani
• Classes Sections
– Sunday ( 8 – 9 AM and 11 AM – 12 PM)
– Tuesday (10 – 11 AM and 11 – 12 PM )
• Text Book:
– Liang, Introduction to Java Programming
Assessments
– Final Exam : 40 points
– Lab Exercises : 20 points
– Midterm : 20 points
– Assign&Quizes (2 + 3) : 20 points
– Total : 100 Points
Review on Basic Programming
• Variables
• Statements (assignment, equality, Math, …)
• Control Structures (Loops, Conditional
Statements)
• Methods
• Arrays
Course Outline
• Introduction, why OOP, advantages…
• Objects and classes.
• Inheritance.
• Polymorphism.
• Exception handling.
• Abstract classes and interfaces.
• Simple data structures such as lists and
queues
Programming Techniques
• Unstructured (or Non-structured) Programming
– A program consists of a sequence of commands or
lines of codes…no functions…uses lables for flow
control …(Spaghetti code)
– Early programs and programming languages such as
Assembly and Fortran used this techniques.
• Structured Programming
– There is a structure in the program which means that
there are entities that can be identified.
• Structured Programming (Cont.)
– There is the concept of a “Procedure” or a
“function”, or “subroutines”…
– Procedural programming is the one in which the
“procedure” or a “function” is the main building
block (such as C…)
• Problem: Global variables…functions have unrestrected
access to data.
– Object Oriented Programming where objects are
the basic building block.
What is and Why Object Oriented
Programming?
• What is?
– The program consists of objects (rather than
functions) that communicate with each other.
• Why?
– Encapsulation (bundling of data with methods that
operate on that data)
– Information/Data hiding (Data is concealed within
the class so that it could not be mistakenly
changed)
• Why OOP?
– Code reuse (Inheritance)…A programmer can take
an already developed code and make additions to
this class without changing the class itself.
• Polymorphism and overloading (means many
shapes)
– The already defines functions and operators can
behave differently depending on the “objects”
they operate upon.
Classes and Objects
– Real life is made of Objects (Car, House, Man, pen, etc…)
– Objects interact with each other
• Ahmed (a man) has a Car and lives in a House.
– In programming languages we have
• Standard data types (int, char, fload, etc…)
• OOP introduced what we call “User-defined data types” (such
as Car, Student, Building)
– Each class has “properties”
• Member variables
• Member functions
Class vs Object
• A data type does not allocate a place in memory
(e.g. int specifies a type, but int x allocates a
memory location called x)
• Defining a class defines a new type without
allocating memory.
– For example class Car, class Student, class House.
• A piece of memory of type Car is allocated by
defining an OBJECT of type Car.
– E.g. Car x (x is of type car)
examples
class Car {
Private:
int year;
char lic_num;
public:
Void get_year(int y);
Void get_lic_num(string ln);
}
Object instances
• Creating new objects of a given class is called
“instantiation”
• Ex:
– Car c1, c2;
• This creates two places in memory with
names c1 and c2 (initialized with zeros or
garbage depending on the compiler)