The theory of a Pong bat
What follows is a hypothetical discussion of how we might use OOP to get started with the Pong project by coding a Bat
class. Don’t add any code to the project just yet as what follows is over-simplified to explain the theory. Later in this chapter, we will code it for real. When we get to coding the class for real, it will be different, but the principles we will learn about here will prepare us for success.
We will begin by exploring variables and functions (or methods) as part of a class.
Declaring the class, variables, and functions
A bat is a real-world thing that has properties, behavior, and a specific appearance. It performs a role; it bounces a ball when it collides with the ball. A bat that bounces a ball is, therefore, an excellent first candidate for a class.
If you don’t know what Pong is, then take a look at this link: https://en.wikipedia.org/wiki/Pong.
Let’s take a look at a hypothetical...