Design Patterns Video Tutorial

Design Patterns Video TutorialHere I begin my design patterns video tutorial. I have talked a great deal about OOP design principles in the past. I’ve shown you how to turn requirements into a UML diagram. Then I covered how to turn a UML diagram into a class.

This tutorial will start off by revisiting OOP concepts. I’ll also provide answers to the most common questions I receive.

By the end, you’ll be able to use design patterns to solve common software design problems.

If you like videos like this, please tell Google by clicking here

Sharing is nice

Code from the Video

public class Animal {
	private String name;
	private double height;
	private int weight;
	private String favFood;
	private double speed;
	private String sound;
	public void setName(String newName){ name = newName; }
	public String getName(){ return name; }
	public void setHeight(double newHeight){ height = newHeight; }
	public double getHeight(){ return height; }
	public void setWeight(int newWeight){ 
		if (newWeight > 0){
			weight = newWeight; 
		} else {
			System.out.println("Weight must be bigger than 0");
	public double getWeight(){ return weight; }
	public void setFavFood(String newFavFood){ favFood = newFavFood; }
	public String getFavFood(){ return favFood; }
	public void setSpeed(double newSpeed){ speed = newSpeed; }
	public double getSpeed(){ return speed; }
	public void setSound(String newSound){ sound = newSound; }
	public String getSound(){ return sound; }
	// A private method can only be accessed by other public methods
	// that are in the same class
	private void bePrivate(){
		System.out.println("I'm a private method");
	public static void main(String[] args){
		Animal dog = new Animal();

public class Dog extends Animal{
	public void digHole(){
		System.out.println("Dug a hole");
	public void changeVar(int randNum){
		randNum = 12;
		System.out.println("randNum in method value: " + randNum);
	/* This private method can only be accessed through using other 
	 * methods in the class */
	private void bePrivate(){
		System.out.println("In a private method");
	public void accessPrivate(){
	// The constructor initializes all objects
	public Dog(){
		// Executes the parents constructor
		// Every class has a constructor whether you make it or not
		// Sets bark for all Dog objects by default

public class Cat extends Animal{
	// The constructor initializes all objects
	public Cat(){
		// Executes the parents constructor
		// Every class has a constructor whether you make it or not
		// Sets bark for all Dog objects by default
	// If you want to make sure a method isn't overridden mark it as Final
	final void attack(){
		// Do stuff that can never change
	// A field marked with final can't be changed
	public static final double FAVNUMBER = 3.14;
	// A class labeled as final can't be extended

public class WorkWithAnimals{
	int justANum = 10;
	public static void main(String[] args){
		Dog fido = new Dog();
		// Everything is pass by value
		// The original is not effected by changes in methods
		int randNum = 10;
		System.out.println("randNum after method call: " + randNum);
		// Objects are passed by reference to the original object
		// Changes in methods do effect the object
		System.out.println("Dog name after method call: " + fido.getName());
		System.out.println("Animal Sound: " + fido.getSound());
		// Create a Dog and Cat object with the super class
		// but the Dog and Cat reference type
		Animal doggy = new Dog();
		Animal kitty = new Cat();
		System.out.println("Doggy says: " + doggy.getSound());
		System.out.println("Kitty says: " + kitty.getSound() + "\n");
		// Now you can make arrays of Animals and everything just works
		Animal[] animals = new Animal[4];
		animals[0] = doggy;
		animals[1] = kitty;
		System.out.println("Doggy says: " +animals[0].getSound());
		System.out.println("Kitty says: " +animals[1].getSound() + "\n");
		// Sends Animal objects for processing in a method
		// Polymorphism allows you to write methods that don't need to 
		// change if new subclasses are created.
		// You can't reference methods, or fields that aren't in Animal
		// if you do, you'll have to cast to the required object
		((Dog) doggy).digHole();
		// You can't use non-static variables or methods in a static function
		// System.out.println(justANum);
		// sayHello();
		// You can't call a private method even if you define it in
		// the subclass
		// fido.bePrivate();
		// You can execute a private method by using another public
		// method in the class
		// Creating a Giraffe from an abstract class
		Giraffe giraffe = new Giraffe();
	// Any methods that are in a class and not tied to an object must
	// be labeled static. Every object created by this class will
	// share just one static method
	public static void changeObjectName(Dog fido){
	// Receives Animal objects and makes them speak
	public static void speakAnimal(Animal randAnimal){
		System.out.println("Animal says: " + randAnimal.getSound());
	// This is a non-static method used to demonstrate that you can't
	// call a non-static method inside a static method
	public void sayHello(){

36 Responses to “Design Patterns Video Tutorial”

  1. Punit says:

    woww man so finally you started with design patterns, please covers as much design patterns as you can.

    • admin says:

      I will definitely do that. I sort of covered design patterns during the last 10 videos of my Java video tutorial. I did it in an interactive manor. This time I’ll do it in a much more straight forward way. Thanks for watching 🙂

  2. Sid says:

    Hello Derek,
    I’m 14 and I am very inspired by your videos. They are extremely informative and funny and I think they compare to the professional one’s on I would like to emulate your awesome approach and try to make some videos myself teaching web design and programming. Could you please make a quick tutorial explaining how to plan, record, edit, and deliver your amazing videos. You don’t have to go over everything but just some basic techniques. Again, awesome videos! Thanks, Sid.

    • admin says:

      Hi Sid, Thank you for all of the kind words 🙂 I pretty much cover what I do in Become a YouTube Partner.

      The only thing that changed since then is that I now record screencasts with Camtasia 2. Apple broke the Quicktime screen capture tool after the last OS upgrade. I also got a Panasonic HDC-TM90 camcorder. It is a fabulous camera for the money. The only thing bad about it is the audio recording. I checked and it looks like you can only find it used? I plan on getting a Zoom H1 Digital Recorder to solve my audio issues.

      As per my style and why I’m different. YouTube tells us to make short videos that are from 3 to 5 minutes in length maximum to maximize earnings. That is why most tutorial people make videos much shorter than I. You are also told to stick with one type of video. I break these and other rules because I don’t particularly care about making money. I also change the way I make videos constantly.

      Feel free to ask any questions. If you want to know how to vlog and make money like the pros, take a look at How to video blog. I go everything in detail there

      • Sid says:

        Thank you for the quick and kind reply. I just have one more quick question. Since you use Camtasia 2, do you still use iMovie to edit you video or does Camtasia have editing features for, say, editing out the pauses in the raw video? Much thanks, Sid.

        • admin says:

          You’re very welcome. I still use iMovie. Camtasias editing features are very poor. I like the cursor highlights and a few other things it brings though

  3. joel says:

    Thank you So Much Derek.Finally your with Design Patterns.Your Tutorials are very Nice.Great Work Once Again

  4. Saleh says:

    I very interested in your Java tutorials. I am starting learning design from here.

    Thank you Derek.

  5. amar says:

    can you please explain why you called super class constructor in the

    i am a new viewer and find your tutorials amazing!

    Thank you as always!

    • admin says:

      Thank you 🙂

      You execute super(); so that you can initialize anything that is needed for the super class of Dog named Animal. This is just to make sure anything that may be needed by Dog is set up properly by the Animal constructor.

      This is kind of a quick review on OOP in Java. I cover the topic more thoroughly here Java OOP Tutorial. You can find all of my Java tutorials in one place on this page Java Video Tutorial. I hope that helps

  6. jawwad hanif says:

    Hi sir, super work sir, i have no words to appriciate u. Good work

  7. abhishek says:


    Your videos really helped me.Where I can find the slides which you used in the tutorial?

    Thanks and Regards,

  8. Siva says:

    Hi Derek,

    Can you provide the link for design patterns where I can find all the tutorials at one place (Links on the right hand side) just like how you have done it for Android Tutorials.


  9. Jean says:


    I can’t thank you enough. Your design pattern and refactoring tutorials have helped me out a lot. I studied electrical engineering, so I never heard of design patterns until I stumbled across your page. I had a job interview for a software engineering position and I was able to answer every technical question thrown at me on design patterns because of your A++ tutorials. Continue the great work!!!


    • Derek Banas says:


      I’m very happy that I could help 🙂 This web site was put together to help people get jobs, so I’m happy that it has done that for some people. You’re very welcome.

  10. stuff says:

    Hi, and thank you for the tutorials!
    @line#81 I think you meant ” Animal giraffe = new Animal(); “

  11. Ayoub says:

    Hello Derek ,

    very useful tutorials , simply ,nicely ,professionally explained , just i want a litle help about the OOP concepts and i would like to share with us any exercices to practice and well understand that OO wOrLd , thanks a lot

  12. Ayoub says:

    hello Derek ,

    it’s good to comment again , to tell you how is very useful to follow your tutorials .
    i want just to ask if there is a tutorial about j2ee patterns ?

    thanks again 🙂

  13. Ratul says:

    Hi Derek,
    First a big thank you for the great training content you provide free of cost. It really makes the Internet a better place as a whole.

    I was wondering if you could post or tell me a more structured way of approaching all this material. My end goal is to be an Android programmer/engineer. I have basic knowledge of Java and data structures but haven’t really dived deep into OO with hands-on large projects yet. I’m confused regarding which of your course material to tackle first – UML, Object Oriented Design or Design Patterns? And then the Android Studio tutorials? Or in some other order?

    It would be really helpful if you could provide a structure to learning your various courses with Android as the destination.

    Thank You once again!!

  14. Zersiax says:

    I am a fully blind computer science student and this is just the resource I needed 🙂 I can follow along with you in the code because you are very verbal in reading out what you are doing, which is a huge plus for me. I needed a resource that takes you from a quick refresher of OO concepts into how they are applied in the various design patterns that are out there, and it seems I have found just that 🙂 keep rockin’ 🙂

    Thanks a lot from the waterlogged Netherlands 😉

  15. Avisekh says:

    Great work ……….spreading knowledge is a divine thing keep it up Derek…………

  16. Mefodii says:

    Thank you 🙂 You really made a great and awesome tutorials

Leave a Reply

Your email address will not be published.