You are on page 1of 16

OBJECT - ORIENTED

PROGRAMMING
Lecturer: MA Lam Hong Thanh
GROUP 3

Ngô Thị Thu Hiền K224111485

Đinh Thiên Lý  K224111489

Lưu Yến Nhi K224111498

Lữ Hồng Quân  K224111500


Defintion

OBJECT
DEFINITION
Declaration

Content ACCESS
MODIFIERS

OBJECT ELEMENTS
Class definition

Object with similar characteristics (properties


and methods) are grouped into a class to
distinguish them from other.

A class is a classification of objects or the type of


an object

Example:
Iphone, samsung, xiaomi, nokia
belong to the smartphone class
Clockwatcher, Alarm clock,
Wristwatch belong to the clock class
Object definition

The concept of object in object-oriented


programming is like a concrete object in
the real world.

Each object has its own properties and


methods:
Properties describe the characteristics
of an object.
Methods are object's behaviours of
operation, called a method for short.
Object definition
Object

Class Mercedes

Lamborghini

car
BMW

Class declaration

class TenLop:
‘’properties declaration
dacdiem1
dacdiem2
dacdiemn

//method declaration
def PhuongThuc1( ):
def PhuongThuc2( ):
Class declaration
Object declaration
class Cnhanvien:
def __init__(self, ms, hoten, ngay)
self.id=ms
self.name=hoten
self.date=ngay
A=Cnhanvien('12','truong van A','22/2/2002')

Optional

object_name = ClassName(argument_1, argument_2, ...., argument_n)

When you create an object for a class, it is called instance of a class


Class variables/ attributes

The syntax to access class variable (attributes of object) is:


object_name.data_attribute_name
The syntax to assign value to data attribute is:
object_name.date_attribute_name = value
Where value can be of integer, float, string types, or another object itself.
The syntax to call method attribute is:
object_name.method_attribute_name()
Class variables/ attributes
Constructor Method
A special method
One constructor per class
If no constructor is declared, the compiler will add the default
constructor by itself
With no return type
The __init__() method, which will be the first method definition of a class
Constructor
class Mobile:
def __init__(self,name):
self.mobile_name = name
def receive_message(self):
print(f''Receive message using {self.mobile_name} Mobile'')
def send_message(self):
print(f''Send message using {self.mobile_name} Mobile'')
def main()
nokia = Mobile("Nokia")
nokia.receive_message()
nokia.send_message()
if __name__=="__main__":
main()
As the __init__() method is automatically initialized, no need to explicitly call it, instead pass the
arguments in the parentheses following the class name when you create a new instance of the class.
Constructor
SELF KEYWORD
Refer to the current instance
In case the parameter name is the same as the class variable name, use self to refer to
the class variable
Constructor
SELF KEYWORD

The self keyword indicates that this is a property or method of the object (you
can use another keyword instead as long as it is at the beginning of the
parameter list):
class MyClass:
a = 10
def func(self):
```noi dung ham
ob = MyClass()
ob.func()
Thank you for listening!

You might also like