Lecture1
Lecture1
Fall 2020/21
Object-Oriented Programming
CS-201, CS201
Lec. (1)
1
CS201 Course Marking
• Scheme
Quiz 1: 20
Quiz 2: 20
Quiz 3: 20
Lab: 30
Final: 60
3
What IS Object Oriented Programming ?
A programming paradigm does not refer to a specific language but rather to a way to build a program
or a methodology to apply.
Some languages make it easy to write in some paradigms but not others.
Some Programming Languages allow the programmer to apply more than one Paradigm.
Example of Programming Paradigms
Example of Previous Programming Paradigm
Procedural Programming
Procedural programming (PP), also known as inline programming takes a top-down approach. It is about writing a
list of instructions to tell the computer what to do step by step. It relies on procedures or routines.
Calc Sum ( )
Calc Average ( ) Calc Sum ( )
Call To function To Calculate Average
Calc Sum ( )
During analysis phase, you need to examine what your program needs to keep data about what?
Faculty Environment
Building
Ex: We found that our program needs to keep data about student. Then the student becomes an object.
Ex: We need to assign every professors to specific courses. Then the professor becomes an object, etc.
In OOP, to identify objects, we concentrate on data required to be kept in my program, rather than concentrate of
function in the procedural paradigm.
Objects in Super market Program
Super Market
Stock
Objects in Car Maintenance Program
Car Maintenance
………
Object Is comprised Of ?
Object
Data
Operations ( )
Operations ( )
1- Modify Price ()
2- Set Discount ()
3- Get Product Name ()
Every object is composed of data and operation(s) 4- Get Product Price ()
Data is the attributes (properties) of the object
Operations(s) are the functions(s) that the object performs using the object’s data
Ex: change the product’s price. We need a function(s) | operation(s) that edit the attribute| property | data member| (price)
Ex: Perform discount on the product. We need a function [setDiscount()] | operation that edit and save the attribute |
property | data member| (discount)
Ex: Report of product. We need a function [getProductName()] | operation that retrieve product name.
Ex: Report of product price. We need a function [getProductPrice()] | operation that retrieve product price.
Object Is comprised Of ?
Student
Data
1Student_name ,
2 University_Id
3 Birth_Date
4Address
5-GPA
6 Study_Level
Operations ( )
1Modify GPA()
2Change Study level ()
3- Get Student Name ()
4- Get Student Address ()
Every object is composed of data and operation(s)
Data is the attributes (properties) of the object
Operations(s) are the functions(s) that the object performs using the object’s data
Object Is comprised Of ?
Car
Data
1Factory,
2 Model
3 Fuel_Capacity
4No_of_doors
5-Color
6- Shape
Operations ( )
1- Set Factory Name()
2- Change Color ()
3- Get Car Info ()
4- ………..
Every object is composed of data and operation(s)
Data is the attributes (properties) of the object
Operations(s) are the functions(s) that the object performs using the object’s data
Object Is comprised Of ?
2. The whole OO program is the set of all identified objects and the relationships
between all of these objects.
3. Every object needs to call operation(s) in other object(s) (i.e., sending messages
between objects)
What is Class ? Why we need It ?
Student 1 Student 2 Student 3
Class Student
Student
Class Student
1 = Ahmad
= 12345
Data: =3.75
=3
1Student_name ,
2University_Id
5-GPA Attribute values:
6- Study_Level Ahmad, 12345, 3.75, 3
Attribute values:
Student
Class Student
1 Ahmad, 12345, 3.75, 3
Data:
1Student_name , = Ahmad Ex: Attribute value (Ahmad) is saved in
2University_Id = 12345
data item | attribute | data member (student_name)
5-GPA =3.75
6- Study_Level = 3 of object (student1)
Operations ( ) Operations:
1Modify GPA()
2Change Study level () Modify GPA()
3- Get Student Name ()
4- Get Student GPA ()
The operations works on the data of Student1 object ONLY
What is Class ? Why we need It ?
Add another student, Student 2.
Create a new object for Student 2
The new object for Student 2 gets new data values
The methods invocation are only for that object
Student
Class Student
2
Data:
1Student_name ,
= Hassan
2University_Id
= 23456
5-GPA
=3.85
6- Study_Level
=2
Operations ( )
1Modify GPA()
2Change Study level ()
3- Get Student Name ()
4- Get Student GPA ()
What is Class ? Why we need It ?
Add another student, Student 2.
Create a new object for Student 2
The new object for Student 2 gets new data values
The methods invocation are only for that object
Student
Class Student
2
Data:
1Student_name , = Hassan
2University_Id = 23456
5-GPA =3.85
6- Study_Level = 2
Operations ( )
1Modify GPA()
2Change Study level ()
3- Get Student Name ()
4- Get Student GPA ()
What is Class ? Why we need It ?
1. Identify objects.
2. Identify every attributes and operations of each object.
3. Put the identified attributes and operations in terms of Class.
4. During program running, create the object of that class and save all its
own values,
and whenever you need to access the object’s data, you need to
invoke its own operations.
Objects and Classes