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 like variables for speed and direction, a RectF for handling collisions and more besides.

As our objects have more in common we should start taking advantage of OOP, inheritance, polymorphism and a 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 disorganised code is hard to read, debug or extend. The bigger the game project and the more object types, the more of ...

Get Learning Java by Building Android Games - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.