Chapter 18: Introduction to Design Patterns and Much More!
Since the second project, we have been using objects. You might have noticed that many of the objects have things in common, things such as variables for speed and direction, a RectF
for handling collisions, and more besides.
As our objects have more in common, we should start taking more advantage of OOP, inheritance, polymorphism, and another concept we will now introduce, design patterns.
Inheritance, polymorphism, and design patterns will enable us to fashion a suitable hierarchy to try and avoid writing duplicate code and avoid sprawling classes with hundreds of lines. This type of disorganized code is hard to read, debug, or extend. The bigger the game project and the more object types, the more of a problem this would become.
This project and the next will explore many ways that we can structure our Java code to make our code efficient, reusable, and less buggy. When we write code to a specific, previously...