0% found this document useful (0 votes)
4 views

Lecture1

The document provides an overview of Object-Oriented Programming (OOP), highlighting its paradigm based on 'objects' and contrasting it with procedural programming. It explains the structure of objects, their attributes, and operations, as well as the concept of classes as blueprints for creating objects. The document also includes examples of objects in various programs, emphasizing the importance of identifying necessary objects and their relationships in OOP.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture1

The document provides an overview of Object-Oriented Programming (OOP), highlighting its paradigm based on 'objects' and contrasting it with procedural programming. It explains the structure of objects, their attributes, and operations, as well as the concept of classes as blueprints for creating objects. The document also includes examples of objects in various programs, emphasizing the importance of identifying necessary objects and their relationships in OOP.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Faculty of Information Technology

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 ?

 Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects"

 A programming paradigm : is a style of programming, a way of thinking about software construction.

 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.

Every routine (function) can be subdivided into (small functions) subroutines


Procedural Programming Example : Program to Calculate Average of Array Items

Code To declare and initialize Array


Get Input ( )

Call To function To Accept Array Data

Calc Sum ( )
Calc Average ( ) Calc Sum ( )
Call To function To Calculate Average

Calc Sum ( )

Procedural programming is a paradigm, a way of thinking


1. Subdivide the program into procedures | routines | functions
2. Build the routine(s) and subroutine(s)
3. Call the routine(s)
 Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects"

Object : is a thing (Tangible – Intangible)

An Object is a thing we need to keep a data about it in my program

During analysis phase, you need to examine what your program needs to keep data about what?

Anything you find it necessary to keep a data about is known as object


Objects in Faculty Management Program

Faculty Environment

Student Course Professor

Class Trans. Resources

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

Product Customer Cashier

Cart Delivery Loyalty


Card

Stock
Objects in Car Maintenance Program

Car Maintenance

Car Customer Spare Part

………
Object Is comprised Of ?

Object
Data

Operations ( )

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 ?
Product
Data
1- Product _name ,
2- Product _code
3Price
4Producer
5-Discount

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 ?

1. Identify the necessary objects

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

Data: Data: Data:


1 Student_name , 1Student_name ,
1Student_name , 2 University_Id 2University_Id
2 University_Id 3 Birth_Date 5-GPA
3 Birth_Date 4 Address 6- Study_Level
4Address 6- Study_Level
5-GPA
6- Study_Level Operations ( ) Operations ( )
1Modify GPA()
1 Modify GPA() 2Change Study level ()
Operations ( ) 2 Change Study level () 3- Get Student Name ()
1Modify GPA() 4- Get Student Address () 4- Get Student Address ()
2Change Study level ()
3- Get Student Name ()
4- Get Student Address ()
What is Class ? Why we need It ?

Class Student

Data: Student 1 Student 3 Student 2


1Student_name , Data: Data: Data:
2 University_Id 1Student_name 1Student_name 1Student_name
2 University_Id 2 University_Id 2 University_Id
3 Birth_Date 3 Birth_Date 3 Birth_Date 3 Birth_Date
4Address 4Address 4Address 4Address
5-GPA 5-GPA 5-GPA 5-GPA
6- Study_Level 6- Study_Level 6- Study_Level
6- Study_Level
Operations ( ) Operations ( ) Operations ( )
Operations ( ) 1Modify GPA()
2Change Study level ()
1Modify GPA()
2Change Study level ()
1Modify GPA()
2Change Study level ()
1Modify GPA() 3- Get Student Name () 3- Get Student Name () 3- Get Student Name ()
2Change Study level () 4- Get Student Address () 4- Get Student Address () 4- Get Student Address ()

3- Get Student Name ()


4- Get Student Address ()
To make sure that all objects have the same attributes and their data types and the same set of
operations, we have to have class which is the blueprint (the standard that all objects of the same
types have the same structure).
Ex: all student objects should have the same data members and the same methods, we have to build
a class “student” contains all the required and data members and the required methods.
Every object is a instance of the class.
What is Class ? Why we need It ?
Class Student
Student 1
Data: Data:
Student 3 Student 2
1Student_name , Data: Data:
1Student_name
1Student_name 1Student_name
2 University_Id 2 University_Id
2 University_Id
3 Birth_Date 2 University_Id
3 Birth_Date 3 Birth_Date 3 Birth_Date
4Address
4Address 4Address 4Address
5-GPA
5-GPA 5-GPA
5-GPA 6- Study_Level
6- Study_Level 6- Study_Level
6- Study_Level 7- Email 7- Email 7- Email
7- Email Operations ( ) Operations ( )
1Modify GPA()
Operations ( )
1Modify GPA()
Operations ( ) 2Change Study level ()
3- Get Student Name ()
2Change Study level ()
1Modify GPA()
2Change Study level ()
3- Get Student Name () 3- Get Student Name ()
1Modify GPA() 4- Get Student Address ()
4- Get Student Address () 4- Get Student Address ()
2Change Study level () 5- Print Student Info ()
5- Print Student Info () 5- Print Student Info ()
3- Get Student Name ()
4- Get Student Address ()
5- Print Student Info ()
If we don’t have a class named “student”, so we have to add manually the email attribute for every
object. The existence of the “student” class allows us to update the class by adding the email attribute,
and the object instantiated from the class are updated with the email attribute.
Ex: Add methods
Ex: change attribute data type
What is Class ? Why we need It ?

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

Operations ( ) Ex: Attribute value (Ahmad) is saved in


1Modify GPA() data item | attribute | data member (student_name)
2Change Study level ()
of object (student1)
3- Get Student Name ()
4- Get Student GPA ()
What is Class ? Why we need It ?

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

– A class is code that describes a particular type of object. It


specifies the data that an object can hold (the object's fields),
and the actions that an object can perform (the object's
methods).

– a class can be considered as a code "blueprint" that can be


used to create a particular type of object.
Objects and Classes

• When a program is running, it can use the


class to create, in memory, as many objects
of a specific type as needed.

• Each object that is created from a class is


called an instance of the class.

You might also like