Becoming Familiar With Interfaces
Interfaces have always been something that I’ve struggled with but after going through Head First Design Patters, I can see I’ll be using them a lot more. I’ve learnt that I never fully understood the purpose of an interface but following along through this book has let me see just how powerful the extra layer of abstraction can be. I’ll probably also be using abstract classes and methods more often because they fill a similar role to interfaces (as well as help cut down on code duplication) and have some pretty useful implementations when paired with interfaces.
The first chapter of the book sets up a situation that is easily relatable and steps through meeting the specifications as they change. At first, the application only needs to simulate the behaviour of different types of ducks. The first solution that is proposed is to create a general class and allow the different kinds of...