Skip to content

Instantly share code, notes, and snippets.

@CaglarGonul
Created April 6, 2013 08:43
Show Gist options
  • Save CaglarGonul/5325431 to your computer and use it in GitHub Desktop.
Save CaglarGonul/5325431 to your computer and use it in GitHub Desktop.
Programming to an interface rather than an implementation.
package com.chp1.simuduck.v3;
public interface Animal {
void makeSound();
}
package com.chp1.simuduck.v3;
public class Dog implements Animal{
@Override
public void makeSound() {
System.out.println("hav hav hav hav");
}
}
package com.chp1.simuduck.v3;
public class Cat implements Animal{
@Override
public void makeSound() {
System.out.println("miyav miyav miyav.");
}
}
@Test
public void test_animal(){
Animal animal = new Dog();
animal.makeSound();
animal = new Cat();
animal.makeSound();
}
hav hav hav hav
miyav miyav miyav.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment