Here I continue my design patterns video tutorial. If you missed part 1, definitely watch it first here Design Patterns Video Tutorial.
In this part of the tutorial I cover polymorphism, abstract classes, abstract methods, interfaces, using static methods and variables and a whole bunch more.
All of the code follows the video to help you learn.
If you like videos like this, telling Google helps [googleplusone]
Sharing is nice [nttfblike]
Code from the Video
Animal.java
Dog.java
Cat.java
WorkWithAnimals.java
Creature.java
Giraffe.java
Living.java
Hi Derek,
In de Living.java is de giraffe-code. Is it possible for you to repair that?
Thanx in advance.
Yours,
Dennis de Vink
I’m sorry, but I’m not sure what you are referring to?
He means, where can I get the code for “living.java”
🙂
What they’re trying to say is that the Living.java content is a cut-n-paste error from Giraffe.java.
Class Name for Living.java is not correct.
It is referred as Giraffe again.
Sorry about that
Thanks for the awesome tutorial. Quick note: the last class “Living.java”, which is supposed to be the Living interface, has got some other code (from Girafe). This is what the guys had noted.
I have a question, is it not possible to “implement” an abstract class?
The way that I have seen is: (say I have your Creature class) and I have my own custom class Snake, I can then do something like
Creature boaConstrictor = new Snake(); //then I also get to //inherit any method, which is not abstract and simply take the //functionality
because my Snake already extends Animal, but I still want to use some functionality (supposedly) available in the Creature class.
Sorry for the long question.
Best Regards,
You’re very welcome 🙂 It definitely would make sense to turn Creature into an interface instead of an abstract class. That would actually be a better option. You normally use abstract when you must force some methods to not be abstract. Since that isn’t the case here it makes more sense for it to be an interface. i hope that helps
I just watched the first two of your Design-Pattern tutorials and I wanna give u a BIG thumbs up! I just have one request: Why don’t you put a dl link for the code package below? Would make it much faster to actually work with the given code.
kind regards
Thank you very much 🙂 Sorry about that. I now provide packages of code for download. I’m learning new things all of the time. Thank you for the input.
I am hoping to take advantage of the opportunity to download the “packages of code” you had refereed to. Is there a link or URL? Pls. could you provide it?
For all of my newer tutorials I provide the complete packages if I think it would help. I didn’t do that with the design patterns because I thought it would cause more confusion because there are so many files.
Could you post another example of an abstract class that you might find in practice? I’m not sure why one would create an abstract class with those fields only to make the getters/setters abstract, that seems to be the perfect place to actually implement the methods and make other methods abstract, right? So while I understand what it is, I’m still not sure how to apply the abstract class concept. Thanks.
You use an abstract class any time when you need a class in which every method can’t be abstract. It doesn’t happen all the time, but you’ll know it when you need it.