blob: c2f7457210fb870c83e8e72740748a3809f9a5c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# Modular Programming
^70725c
## 1. Introduction
- A. What is Object-Oriented Programming?
- B. Why use OOP? (vs. procedural)
- C. Real-world analogies (e.g., modeling components like pumps, motors, or vehicles)
## 2. Core OOP Concepts
- A. **Classes and Objects**
- Definitions
- Syntax in Python
- B. **Attributes and Methods**
- Instance variables
- Functions inside classes
- C. **Encapsulation**
- Public vs private variables
- Using `__init__` and `self`
- D. **Inheritance**
- Parent and child classes
- Reuse and extension of code
- E. **Polymorphism** _(brief overview)_
- Method overriding
- Flexibility in interfaces
## 3. Python OOP Syntax and Examples
- A. Define a simple class (e.g., `Spring`)
- B. Instantiate objects and use methods
- C. Show `__init__`, `__str__`, custom methods
- D. Add a derived class (e.g., `DampedSpring` inherits from `Spring`)
## 4. Engineering Applications of OOP
- A. Modeling a mechanical system using classes
- Example: Mass-Spring-Damper system
- B. Creating reusable components (e.g., `Material`, `Beam`, `Force`)
- C. Organizing simulation code with OOP
## 5. Hands-On Coding Activity
- A. Write a class for a basic physical component (e.g., `Motor`)
- B. Add behavior (e.g., `calculate_torque`)
- C. Extend with inheritance (e.g., `ServoMotor`)
- D. Bonus: Integrate two objects to simulate interaction
|