Pythonlearn 11 Object Oriented Programming Part 1
Pythonlearn 11 Object Oriented Programming Part 1
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:
9
What is the Object Lifecycle?
• The Object Lifecycle consists of three main stages:
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:
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:
31