Created
April 6, 2013 08:43
-
-
Save CaglarGonul/5325431 to your computer and use it in GitHub Desktop.
Programming to an interface rather than an implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.chp1.simuduck.v3; | |
public interface Animal { | |
void makeSound(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.chp1.simuduck.v3; | |
public class Dog implements Animal{ | |
@Override | |
public void makeSound() { | |
System.out.println("hav hav hav hav"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.chp1.simuduck.v3; | |
public class Cat implements Animal{ | |
@Override | |
public void makeSound() { | |
System.out.println("miyav miyav miyav."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test_animal(){ | |
Animal animal = new Dog(); | |
animal.makeSound(); | |
animal = new Cat(); | |
animal.makeSound(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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