0% found this document useful (0 votes)
3 views31 pages

Pythonlearn 11 Object Oriented Programming Part 1

The document outlines the fundamentals of Object-Oriented Programming (OOP), emphasizing its importance in designing modular, reusable, and maintainable code. Key principles include encapsulation, abstraction, inheritance, and polymorphism, with practical applications illustrated through managing student data. It also discusses the object lifecycle, access modifiers, and the benefits of modular design.

Uploaded by

kietmethit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views31 pages

Pythonlearn 11 Object Oriented Programming Part 1

The document outlines the fundamentals of Object-Oriented Programming (OOP), emphasizing its importance in designing modular, reusable, and maintainable code. Key principles include encapsulation, abstraction, inheritance, and polymorphism, with practical applications illustrated through managing student data. It also discusses the object lifecycle, access modifiers, and the benefits of modular design.

Uploaded by

kietmethit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Fundamentals of Object-

Oriented Programming (OOP)

1
Why Learn OOP?
• Example: How managing student data at FPT
University efficiently ?

2
Why Learn OOP?
• Helps design modular, reusable, and
maintainable code.
• Widely used in industries like software
development, AI, and IoT.
• Enhances your ability to model real-world
problems programmatically.

3
Key Principles of OOP

4
Key Principles of OOP
• Encapsulation: Protecting data by bundling it with
methods.
• Abstraction: Hiding unnecessary details from the user.
• Inheritance: Creating new classes from existing ones.
• Polymorphism: Allowing different classes to respond to
the same function call.

5
Real-World Analogy
• A class is a blueprint for creating objects.
• Example:

Class: Student
Objects: "Nam (AI19b02)"
"Mai (SE22b01)"

6
What is a Class?
• A class is a user-defined data type that acts as a
blueprint for creating objects.

7
What is an Object?
• An object is an instance of a class.

8
Practical Applications
• Example:

Managing student records at FPT University:

Student class for student details.


Course class for course information.
Grade class for student grades.

9
What is the Object Lifecycle?
• The Object Lifecycle consists of three main stages:

Creation: When an object is instantiated using


the __init__ method.
Usage: When the object is used in a program
(accessing attributes, calling methods).
Destruction: When the object is deleted or goes
out of scope, triggering the __del__ method (if
defined).
10
What is the Object Lifecycle?

11
What is the Object Lifecycle?

12
What is Encapsulation?
• Encapsulation means bundling data and methods into
a single unit and restricting access to some of the
object's components.

13
Access Modifiers
• Public: Accessible everywhere.
• Private: Accessible only within the class.
• Protected: Accessible within the class and subclasses.

14
Access Modifiers
• Public: Accessible everywhere.

15
Access Modifiers
• Private: Accessible only within the class.

16
Access Modifiers
• Protected: Accessible within the class and subclasses.

17
Getters and Setters
• Modifying a student's grade securely.

18
Getters and Setters
• Modifying a student's grade securely.

19
What is Abstraction?
• Abstraction focuses on hiding implementation details
and exposing only the essential features to the user.

20
Examples of Abstraction
• Example:

A StudentManagement system that abstracts the


process of retrieving and managing student data.

→Users interact with a simplified interface (e.g.,


"Get Grades") without knowing how data is
fetched or processed internally.

21
Implementing Abstraction
• Use of abstract base classes (ABCs) with the abc
module.

22
Using Abstraction

23
Using Abstraction

24
What is Modular Design?
• Dividing a program into smaller modules to improve
reusability and maintainability.
• A student management system with modules for
attendance, grades, and courses.

25
Benefits of Modular Design
• Code reuse across multiple projects.
• Easier debugging and testing.
• Simplifies collaboration among developers.
•Pie chart: Benefits distribution (50% reusability, 30%
maintainability, 20% debugging).

26
Example: Modular Program
• Code reuse across multiple projects.
• Easier debugging and testing.
• Simplifies collaboration among developers.
•Pie chart: Benefits distribution (50% reusability, 30%
maintainability, 20% debugging).

27
Key Concepts Recap
• Classes and objects: Blueprints and instances.
• Encapsulation: Protecting data and methods.
• Abstraction: Hiding unnecessary details.
• Modular Design: Breaking down problems into
smaller, manageable parts.

28
Quiz: Basic Concepts
• Question:
"What is the main difference between a class and an
object?"
• Options:
A. A class is an instance of an object.
B. A class is a blueprint; an object is an instance.
C. Objects contain data, while classes are data
structures.

29
Discussion Prompt
• How can encapsulation improve the security of
student records at FPT University?

30
Recommended Reading
• Resources:

Python documentation: https://docs.python.org


PY4E by Dr. Chuck: https://www.py4e.com

31

You might also like