Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Dog.java
- public interface MyDog {
- public void sleep();
- public void eat();
- public void printAll();
- }
- //MyDogImpl.java
- public class MyDogImpl implements MyDog {
- public void sleep() {
- System.out.println("mydog sleep");
- }
- public void eat() {
- System.out.println("mydog eat");
- }
- public void printAll() {
- sleep();
- eat();
- }
- }
- //NewDog.java
- public interface NewDog {
- public void sleep();
- public void eat();
- }
- //NewDogImpl.java
- public class NewDogImpl implements NewDog {
- public void sleep() {
- System.out.println("new dog sleep");
- }
- public void eat() {
- System.out.println("new dog eat");
- }
- }
- //NewDogAdapter.java
- public class NewDogAdapter implements MyDog {
- NewDog newDog;
- public NewDogAdapter(NewDog newDog) {
- this.newDog = newDog;
- }
- public void sleep() {
- newDog.sleep();
- }
- public void eat() {
- newDog.eat();
- }
- public void printAll() {
- sleep();
- eat();
- }
- }
- //AdapterExample.java
- public class AdapterExample {
- public static void main(String[] args) {
- //기존 코드
- MyDogImpl myDog = new MyDogImpl();
- myDog.eat();
- myDog.sleep();
- myDog.printAll();
- //추가된 new dock 사용
- NewDogImpl newDog = new NewDogImpl();
- newDog.eat();
- newDog.sleep();
- newDog.sleep();
- newDog.eat();
- //adapter 사용
- MyDog newDogAdapter = new NewDogAdapter(newDog);
- newDogAdapter.eat();
- newDogAdapter.sleep();
- newDogAdapter.printAll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement