Adapter - Telephone articles
A few days ago, a friend told me his phone number. I was copied on a small piece of paper, and then put it in a book. I didn't expect my wife to post this book. If this is wrong, when I have important things and friends, there is no way to contact. The book has been mail, this is an uncharged fact, calling a friend to say an important thing, it must be done. These cannot be transferred in my will. What should I do? There is also a modern communication tool - phone, I can call the little scorpion, let him tell me not to get?
I have a good reason to return, let's get started.
1. Here, first define a book (PostedBook) class:
Public class postedbook {
/ / Get the phone number I want from the book
Public void gettelcodefrombook () {
System.out.println ("get the phone number!");
}
}
2, define a class that calls a friend (teltofriend):
Public class teltofriend {
Public void telsaything () {
System.out.println ("said important things!");
}
}
3, define get a call (Telphone) class:
Public class telphone extends teltofriend {
Private postedbook postedbook;
Public Telphone (Postedbook Postedbook) {// Phone About Mail
this.postedbook = postedbook;
}
Public void gettelcode () {// get a phone number from the mail book
Postedbook.gettelcodefrombook ();
}
}
4, write test classes:
Public class test {
Public static void main (string args []) {
Postedbook postedbook = new postedbook (); // The book
Telphone telphone = new telphone;
Telphone.gettelcode (); // Get a friend's phone number
Telphone.telsaything (); // and friends say important things
}
}
5. Description:
A: The purpose of Adapter mode is to use two unrelated classes to be used together. In this case, the book and the phone call to a friend is two winds and horses, it is because of a call. The number allows them to be associated, but the premise of getting this number is that I have to call first, so I have completed my purpose by phone.
B: I got the phone number you want by calling this coordination class, and I also said something with my friends.