From 4abc43cdcb7fba399d5377481dd88e54b2db8cb6 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Thu, 24 Apr 2025 15:31:56 -0600 Subject: Added tex file structure for each module --- book/module1/classes_and_objects.tex | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 book/module1/classes_and_objects.tex (limited to 'book/module1/classes_and_objects.tex') diff --git a/book/module1/classes_and_objects.tex b/book/module1/classes_and_objects.tex new file mode 100644 index 0000000..cb9f7ec --- /dev/null +++ b/book/module1/classes_and_objects.tex @@ -0,0 +1,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} -- cgit v1.2.3