Computer Programming Lec1
Computer Programming Lec1
Programing
م دعاء خالد عبد الرضا.م
first Stage
2024-2023
Lecture 1
Introduction to OOP concepts
Object-oriented programming
• is a programming approach that aims to organize programs by
breaking them down into a set of objects that interact with each
other.
• Object-oriented programming is characterized by its focus on objects,
which are entities that represent concepts and things in reality, such
as cars, employees, books, and others.
• Each object carries certain properties and can perform specific
actions
Oop includes several key concepts:
1. Objects: are the actual objects that represent program concepts
and carry data and behavior.
❖Simply put, objects are the things we work with in a program, while
classes are the structures that define how objects are structured and
behave
Objects and Classes
• Example1:
class person:
def __init__(self,name):
self.name =name
person1=person(“ali")
print(person1.name)
#output: ali
Objects and Classes
In this example:
•We define a class called Person.
•The class has a constructor method _init_ that initializes the person’s
name attribute.
•We create an instance of the Person class named person1 with the
name “ali”.
•We access and print the name attribute of the person1 object, which
outputs “ali”.
Objects and Classes
Example2:
class dog:
def _ init _(self ,name, breed):
self.name =name
self . breed = breed
def bark(self):
return"woof!"
dog1 = dog("buddy","golden retrever")
dog2 = dog("max","labrador")