\newpage

\section{Class and Object}
\label{sec:class_and_object}

\subsection{Class}

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects. An object is a data structure that contains both attributes (data) and methods (operations), which together define its behavior.

\vspace{1em}
A class is a user-defined data type that serves as a blueprint for creating objects. It specifies the structure and shared behavior of a category of objects, including default values for attributes and common implementations of methods\footnote{An action that an object can perform.}.

\subsection{Object}
An object is an instance of a class. Each object encapsulates attributes and methods. Attributes store information or properties specific to the object (typically as fields in a data table), while methods define how the object behaves or interacts with other objects.


\vspace{1em}
 All objects in the package are typed. The currently defined and used types are: \tkzNameObj{point}, \tkzNameObj{line}, \tkzNameObj{circle}, \tkzNameObj{triangle}, \tkzNameObj{conic}, \tkzNameObj{quadrilateral}, \tkzNameObj{square}, \tkzNameObj{rectangle}, \tkzNameObj{parallelogram},  \tkzNameObj{regular\_polygon}, \tkzNameObj{occs} and \tkzNameObj{path}.


\subsubsection{Creating an object}
Objects are generally created using the method \tkzMeth{obj}{new}, by providing points as arguments.

\begin{itemize}
  \item The \tkzClass{point} class requires two real numbers (coordinates),
  \item The \tkzClass{regular\_polygon} class requires two points and an integer (the number of sides),
  \item The \tkzClass{occs} class requires a line and a point,
  \item The \tkzClass{path} class requires a table of points written as strings.
\end{itemize}

Each object is usually assigned a name and stored in a table according to its type. For example:
\begin{itemize}
  \item points are stored in the global table \code{z},
  \item lines in \code{L}, circles in \code{C}, triangles in \code{T}, and so on.
\end{itemize}

This convention allows easy access and reusability across computations and drawings. For example:

\begin{mybox}
\begin{verbatim}
z.A = point(1, 2)
z.B = point(4, 5)
L.AB = line(z.A, z.B)
\end{verbatim}
\end{mybox}

\noindent
Here, \code{z.A} and \code{z.B} store points in table \code{z}, while the line defined by these points is stored as \code{L.AB} in table \code{L}.

\vspace{1em}
\tkzRHand{} \textbf{Note:} \\
From version 4 onwards, object creation has been streamlined. Instead of calling \code{object:new(arguments)}, you can simply use \code{object(arguments)} — the shorter form is equivalent.

\begin{mybox}
\begin{verbatim}
z.A = point(1, 2)           -- short form
-- equivalent to:
z.A = point:new(1, 2)
\end{verbatim}
\end{mybox}

Objects can also be generated by applying methods to existing objects. For instance, \code{T.ABC:circum\_circle()} produces a new \tkzClass{circle} object. Some object attributes are themselves objects: \code{T.ABC.bc} returns a \tkzClass{line} representing side BC of triangle ABC.

\vspace{1em}
\tkzRHand{} \textbf{Important:} \\
All these named objects are stored in global tables. To avoid conflicts or residual data between figures, it is strongly recommended to call the function \tkzFct{init\_elements()} at the beginning of each construction. This resets the environment and ensures a clean setup. See the next section

\subsubsection{Initialization: \tkzFct{tkz-elements}{init\_elements}}

Before performing geometric constructions or calculations, it is important to initialize the system. The function \tkzFct{tkz-elements}{init\_elements()} resets internal tables and parameters to prepare for a new figure. This step ensures a clean environment and avoids interference from previously defined objects.

\begin{mybox}
\begin{verbatim}
init_elements()
\end{verbatim}
\end{mybox}

\paragraph{Purpose.}
The function \code{init\_elements} clears global tables such as:
\begin{itemize}
  \item \tkzname{z} — for storing points,
  \item \tkzname{L}, \tkzname{C}, \tkzname{T}, etc. — for lines, circles, triangles,
  \item and other geometric structures.
\end{itemize}
It also (re)sets default values for internal constants such as the number of decimal digits and the floating-point tolerance.

\paragraph{When to use it.}
This function should be called:
\begin{itemize}
  \item at the beginning of each new TikZ figure using Lua,
  \item or any time you need to reset the environment manually.
\end{itemize}

\paragraph{Example.}
Here is a typical usage:

\begin{center}
  \begin{tkzexample}[code only]
  \directlua{
    init_elements()
    z.A = point(0, 0)
    z.B = point(3, 4)
    L.AB = line(z.A, z.B)}
  \end{tkzexample}
\end{center}

\paragraph{Note.}
Calling \code{init\_elements} is optional if you manage object names carefully, but it is highly recommended in iterative workflows or automated figure generation to avoid unwanted data persistence.

\subsubsection{Attributes}
 \label{ssub:attributes}

Attributes are accessed using the standard method. For example, |T.pc| retrieves the third point of the triangle, and |C.OH.center| retrieves the center of the circle. Additionally, I have added a method \tkzMeth{obj}{get()} that returns the points of an object. This method applies to straight lines (pa and pc), triangles (pa, pb, and pc), and circles (center and through).

\vspace{1em}
\noindent
  \textbf{Example}: |z.O,z.T = C.OT:get()| retrieves the center and a point of the circle.

\subsubsection{Methods}
\label{ssub:methods}

A method is an operation (function or procedure) associated (linked) with an object.

Example:   The point object is used to vertically determine a new point object located at a certain distance from it (here 2). Then it is possible to rotate objects around it.

\begin{verbatim}
\directlua{
      init_elements()
      z.A = point(1,0)
      z.B = z.A:north (2)
      z.C = z.A:rotation (math.pi/3,z.B)
      tex.print(tostring(z.C))
}
\end{verbatim}

\directlua{
   init_elements()
   z.A = point (1,0)
   z.B = z.A : north (2)
   z.C = z.A : rotation (math.pi/3,z.B)
   tex.print(tostring("The coordinates of $C$ are: " .. z.C.re .." and "..z.C.im))
}
\endinput