summaryrefslogtreecommitdiff
path: root/book/module1/classes_and_objects.tex
blob: b783048f0db24d45cff407e422a21527363cbab8 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
\section{Modular Programming}\label{modular-programming}

\subsection{1. Introduction}\label{introduction}

\begin{itemize}
\tightlist
\item
  A. What is Object-Oriented Programming?
\item
  B. Why use OOP? (vs.~procedural)
\item
  C. Real-world analogies (e.g., modeling components like pumps, motors,
  or vehicles)
\end{itemize}

\subsection{2. Core OOP Concepts}\label{core-oop-concepts}

\begin{itemize}
\tightlist
\item
  A. \textbf{Classes and Objects}

  \begin{itemize}
  \tightlist
  \item
    Definitions
  \item
    Syntax in Python
  \end{itemize}
\item
  B. \textbf{Attributes and Methods}

  \begin{itemize}
  \tightlist
  \item
    Instance variables
  \item
    Functions inside classes
  \end{itemize}
\item
  C. \textbf{Encapsulation}

  \begin{itemize}
  \tightlist
  \item
    Public vs private variables
  \item
    Using \texttt{\_\_init\_\_} and \texttt{self}
  \end{itemize}
\item
  D. \textbf{Inheritance}

  \begin{itemize}
  \tightlist
  \item
    Parent and child classes
  \item
    Reuse and extension of code
  \end{itemize}
\item
  E. \textbf{Polymorphism} \emph{(brief overview)}

  \begin{itemize}
  \tightlist
  \item
    Method overriding
  \item
    Flexibility in interfaces
  \end{itemize}
\end{itemize}

\subsection{3. Python OOP Syntax and
Examples}\label{python-oop-syntax-and-examples}

\begin{itemize}
\tightlist
\item
  A. Define a simple class (e.g., \texttt{Spring})
\item
  B. Instantiate objects and use methods
\item
  C. Show \texttt{\_\_init\_\_}, \texttt{\_\_str\_\_}, custom methods
\item
  D. Add a derived class (e.g., \texttt{DampedSpring} inherits from
  \texttt{Spring})
\end{itemize}

\subsection{4. Engineering Applications of
OOP}\label{engineering-applications-of-oop}

\begin{itemize}
\tightlist
\item
  A. Modeling a mechanical system using classes

  \begin{itemize}
  \tightlist
  \item
    Example: Mass-Spring-Damper system
  \end{itemize}
\item
  B. Creating reusable components (e.g., \texttt{Material},
  \texttt{Beam}, \texttt{Force})
\item
  C. Organizing simulation code with OOP
\end{itemize}

\subsection{5. Hands-On Coding Activity}\label{hands-on-coding-activity}

\begin{itemize}
\tightlist
\item
  A. Write a class for a basic physical component (e.g., \texttt{Motor})
\item
  B. Add behavior (e.g., \texttt{calculate\_torque})
\item
  C. Extend with inheritance (e.g., \texttt{ServoMotor})
\item
  D. Bonus: Integrate two objects to simulate interaction
\end{itemize}