Saying Qianlong, and Shen Xiaolan three people cruise the Beijing, and I came to a village on the other day, and the village had a family lived a beautiful girl and her mother old lady. The girl likes three things: food, shopping, travel, but these three things are the old lady's most disgust, she wants their daughter to do two things: reading, practice, but the girl is headache.
Qianlong knew that these things wanted to investigate the ability of the two ministers, so he gave him, Ji Xiaolan for three days, see who can put the girl to hand, let and apply.
And Shen Xin thought, is this still don't do it? I have a good girl, Eating, Shopping, Traveling Three strokes got her. And the application, they are money, the first day, the girl is very satisfied, did not expect the old lady, put and remember, said that he is a small mix of the unpredictable, never let go. And the application of the girl plan to fail to end.
Ji Xiaoyu thought, I can't be like Shen, I have to settle the secret with the girl. When I go out, I have to say that the old lady loves to listen. It is actually the girl loves, says a set, so Both people can get it. The secret number is as follows:
Reading: The old lady thought it was going to study, and I actually went to eat and shopping.
Writing: The old lady thought it was to practice, and I actually went to Travelling.
This card is actually an adapter. It turns the external interface from the girl hopes Eating, Shopping, Traveling into Reading and Writing of the old lady, so that it can pass the old lady; but actually do it or the girl hope Eating, Shopping, TRAVELING, so girl is also satisfied.
Haha, this should be a good time, say a set! Things look from the surface is a matter, in fact, the internal implementation may be another thing. Finally, it is Ji Xiaoyu to win the heart.
Below we use the code to tell this story:
Adapter.cs
Using system; use system.collections.gener; using system.text; namespace adapter ... {// Girl hope interface: But because the old lady doesn't like these things, I can't directly use public class girl ... {public void Eating () ... {system.console.writeline ("Don't use it, I want to eat hairy crabs!"); System.console.writeline ();} public void shopping () ... {system.console.writeline "No need to install, buy a very popular small vest this year!"); System.console.writeline ();} public void travelling () ... {system.console.writeLine ("No need to install, back mountain is a Nice place! "); System.console.writeline ();}} // Old lady hopes the interface: If you want to come out, you must tell the old lady, we are going to do what you like to go public interface Mother. ... {void reading (); void Writing ();} // Ji Xiaoyu and girl's agreement, essence is what customers like, let him see what, actually do or the original set of Public Class Agreement: Mother ... {Girl Girl = New Girl (); // Say is to read, is it to give the old lady (client), actually? Public void reading () ... {girl.eating (); girl.shopping ();} public void Writing () ... {girl.travelling ();}}} client: client.cs