This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
So I just finished Head First Java and I'm looking to patch up a couple of misconceptions I'm having. First off, interfaces: how in the world are these useful at all?
It seems to me that going to the trouble of writing an interface and then implementing it in your classes is nothing more than a way of annotating said classes with an additional IS-A marker. EX: Wolf isn't just a Canine, he is also a PredatoryCreature.
But is that really all that helpful, when the methods contained within PredatoryCreature can't contain a body? Sure, they remind you to make sure that Wolf isn't just going to eat(), drink(), and sleep(), that Wolf needs to override methods like attack(), and growl(). but surely there is more to interfaces than a compile-time reminder to override some methods?
Unless their whole usefulness lies in the fact that implementating PredatoryCreature means that I can pass Wolf and some other PredatoryCreature to a method that should only accept PredatoryCreatures? I guess that would be a practical application of adding another IS-A flag to a class....but I could also have just added a boolean value to all my dogs.