Classes

Classes and API’s #

In object-oriented programming, classes can be thought of as the building blocks of an API. A well-designed class encapsulates its functionality and provides a clear and consistent interface for other components to use. This interface can be thought of as the class’s API, e.g., Quadrille class.

When a developer creates a class, she is defining a new component that can be used by other parts of a program, e.g., suppose both Rectangle and Car are part of a much greater encompassing app or even by other programs altogether, e.g., the Quadrille class which represents the whole library source code. By designing a class with a clear and well-documented API, developers can make it easier for other developers to use their code and build on it.

In the realm of software development, classes serve as structured blueprints to encapsulate and organize code. As highlighted in the preceding chapter, one can craft robust applications by predominantly harnessing the power of library APIs without a deep immersion into custom class creation. Furthermore, the developer community is increasingly leaning towards the elegance of functional programming over the intricacies of OOP in various scenarios. Drawing a parallel between the programmer roles discussed over the last two chapters, this one delves into the nuanced considerations of class design, using classes in p5. Subsequent sections will elucidate foundational OOP principles, including inheritance and polymorphism.