summaryrefslogtreecommitdiff
path: root/book/module1/classes_and_objects.tex
blob: cb9f7eca38d25d2c2788b323d7036a5f59fb9c38 (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
\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}

\begin{longtable}[]{@{}
  >{\raggedleft\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.0556}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\raggedleft
\#\# 2. Core OOP Concepts - A. \textbf{Classes and Objects} -
Definitions - Syntax in Python - B. \textbf{Attributes and Methods} -
Instance variables - Functions inside classes - C.
\textbf{Encapsulation} - Public vs private variables - Using
\texttt{\_\_init\_\_} and \texttt{self} - D. \textbf{Inheritance} -
Parent and child classes - Reuse and extension of code - E.
\textbf{Polymorphism} \emph{(brief overview)} - Method overriding -
Flexibility in interfaces
\end{minipage} \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\#\# 3. Python OOP Syntax and Examples - A. Define a simple class (e.g.,
\texttt{Spring}) - B. Instantiate objects and use methods - C. Show
\texttt{\_\_init\_\_}, \texttt{\_\_str\_\_}, custom methods - D. Add a
derived class (e.g., \texttt{DampedSpring} inherits from
\texttt{Spring}) \\
\end{longtable}

\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}

\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}

\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}