Adapter mode: Rural small group to marry Ukrainian beauty language does not pass translation software meritorious

Source: Internet
Author: User

Do not know when to start, always hear "XXX boy Marry Ukrainian Beauty" news, such as rural small man to marry Ukrainian beauty language not through translation software meritorious and so on, I carefully read a few news, found incredibly not the title party, the Ukrainian sister in the news is really good, on a few pictures:

After reading these news and photos, I have three questions in my mind;
1. Does Ukraine really have many beauties?
2. Why do Ukrainian beauties love marrying Chinese men?
3. Translation software can be converted into magic, software development process can reference it?

After a lot of research, I came to the answer:

1. Does Ukraine really have many beauties?

Answer: Yes.
-First from the world map can be seen, Ukraine is located in Eastern European countries at the junction of more than 110 national ethnic groups, the number of intermarriage among the more, over time led to a higher proportion of half-breed beauty.
-Moreover, Ukraine's climate environment is also relatively dependent, the cold more hot and less heat, direct sunlight time is short, resulting in most girls skin fair.
-In addition, Ukrainian girls pay special attention to appearance, dress more sophisticated fashion.

2. Why do Ukrainian beauties love marrying Chinese men?

A: In addition to the subjective factors, there are two objective factors are very important.
-Ukraine is not rich in recent years, and it is still a long way from the capitalist developed countries in our hearts. On the one hand, production stagnation, economic growth is weak, on the other hand, Ukraine also faces the war caused by currency devaluation, foreign capital outflow, rising prices and other pressures, fiscal "only out", the whole country "dry" foreign exchange reserves. So many Ukrainian girls choose to marry outside.
-In addition, because of cultural, social welfare and other reasons, many Ukrainian men have the habit of drinking alcohol, lazy, and Chinese men in the international give a thoughtful, hardworking, family-oriented image, so compared to the Chinese men is a better choice.

3. Translation software can be converted into magic, software development process can reference it?

Translation software converts a guy's Chinese into Ukrainian, which is a "reuse"in the software development process! What is the design pattern that can achieve this effect?

Let's start with a simulation to implement the following translation process:

A. First define a small goal, that is, you can speak Ukrainian with sister, Savadica Emith Oil ~

/** * description:目标:说乌克兰语 * <br/> * author: shixinzhang * <br/> * data: 9/18/2016 */publicinterface Ukrainian {    /**     * 说乌克兰语,比如:Я люблю тебя      * @param string     */    void sayUkrainian(String string);}

B. However, the ideal is very plump, the reality is very skinny, the boy will only Chuan Pu:

/** * description:实际情况:只会中文 * <br/> * author: shixinzhang * <br/> * data: 9/18/2016 */publicclass Chinese {    /**     * 说中文,比如:刘奶奶找牛奶奶买榴莲牛奶     * @param string     */    void sayChinese(String string) {        System.out.println("【中文版】 " + string);    }}

C. This time the translator is on the stage, and it is the artifact that helps the boy to speak Ukrainian:

/** * Description: Translation * < br/> * Author:shixinzhang * <br/> * data:9/18/2016 */ public  class  translator  implements  ukrainian  {     Private  Chinese Mchinese; public  translator  (Chinese Chinese)    {Mchinese = Chinese; }  @Override  public  void  sayukrainian  (String string) {    Omit the complex syntax translation process and imagine  Mchinese.saychinese (string); }}

D. You can see that the translator holds a reference to a Chinese-language guy, implements the Ukrainian-speaking interface, and, in the need to speak Ukrainian, after the grammar translation, the final call of the boy's Chinese:

@Test    publicvoidtestAdapterPattern(){        new Chinese();        new Translator(me);        ukrainianMan.sayUkrainian("我爱你");    }

E. translation + Chuan man = Ukrainian reach, running result:

F. Draw a UML diagram of the above process:

    • The target class, which can speak Ukrainian, is an interface;
    • The actual situation, that is, can only speak Chinese, is a formed, can not change the class;
    • Middleman, that is, translation software, to achieve the target interface (Ukrainian), citing the actual situation (Chinese guy), after rescue, let the Chinese boy has a new function
    • Client clients, Ukrainian sister, want to be able to communicate with Ukrainian language, because the translation software implements the Ukrainian language interface, so you can directly instantiate a translation software as a Ukrainian language person.
@Test    publicvoidtestAdapterPattern(){        new Chinese();        new Translator(me);        ukrainianMan.sayUkrainian("我爱你");    }
This is Adapter Mode, also known as Packaging ModeDefined

Transforms the interface of one class into another interface that the customer wants.
The adapter mode enables incompatible interfaces to become compatible, which can be reused.

A very vivid example.

The adapter pattern is divided into two main types: Class Adapter and Object Adapter 1. Object Adapter, and is associated with the class being adapted

The example above is the adapter. The Adapter holds a reference to the object that is being adapted to the class, so it is called an object adapter.
The UML diagram of the object adapter is consistent with the above example, so it is not listed as a lazy thief.

2. Class Adapter, and the class being adapted is an inheritance relationship

Adapter can invoke methods that are adapted to a class by inheriting the class.
For a chestnut, translation intermediary under the class adapter:

/** * description: 类适配器下的翻译中介 * <br/> * author: shixinzhang * <br/> * data: 9/20/2016 */publicclass ClassTranslator extends Chinese implements Ukrainian {    @Override    publicvoidsayUkrainian(String string) {        sayChinese(string);    }}

The translation software, which adopts the class adapter mode, inherits the Chineseof the adaptive class and implements the target interface Ukrainian, which makes the Saychinese (String) method that cannot be used can be called.

When called:

    @Test    publicvoidtestClassAdapterPattern(){        new ClassTranslator();        ukrainianMan.sayUkrainian("刘奶奶找牛奶奶买榴莲牛奶");    }

Compare the code of the object adapter:

/** * description: 翻译 * <br/> * author: shixinzhang * <br/> * data: 9/18/2016 */publicclass Translator implements Ukrainian {    private Chinese mChinese;    publicTranslator(Chinese chinese) {        mChinese = chinese;    }    @Override    publicvoidsayUkrainian(String string) {        mChinese.sayChinese(string);    }}
As you can see, the object adapter supports passing in an adapter object, so you can do adaptable to a variety of adapter interfaces, and the class adapter inherits directly and cannot be modified dynamically, so the object adapter is generally used more broadly. Use the scene: just want to reuse, do not want to create more!
    1. Usually used in the late software development or maintenance period, because this interface may have been put into use, but the new requirements are not very consistent with, we want to reuse the original interface as much as possible, so use the adapter to wrap.
      .
    2. Or at the beginning of the design is unreasonable, similar functions, due to parameters or names and other small reasons can not be reused, but also consider packaging.
It's a good thing to see in "Big Talk design mode."
    • Design a unified interface beforehand
    • A timely reconstruction of the problem (the worst)
    • Cannot be changed can only be adapted (lower)
Postscript

Speaking of adapter Adapter, the most familiar is the ListView and Recyclerview adapter, originally prepared to write the next article in the ListView source adapter mode, but considering the ListView also has the Observer mode , So the next step is to summarize the observer pattern, and then unify the ListView source parsing .

The difference between the adapter mode and the proxy mode can be seen from the methods called by our two design modes:
    1. The adapter mode is called when emphasizing "end to convert to the destination interface", in this case, Translator ultimate goal is to become a Ukrainian:
      Ukrainian ukrainianman = new Translator (me);
      The client then calls the Ukrainian method
    2. And the proxy mode is through the proxy, intercept calls, and finally to the proxy class to complete the work, in my article http://blog.csdn.net/u011240877/article/details/52264283 for example:
      Agent SONGJJ = new Agent (Baoqiang, false);
Summarize:

The adapter mode is designed to match the final interface,
The proxy mode is for interception and processing purposes.

code address point here

Adapter mode: Rural small group to marry Ukrainian beauty language does not pass translation software meritorious

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.