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 ...

Get Learning Java by Building Android Games - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.