As an object's creation pattern, polymorphic classes in polymorphic patterns can have multiple instances, and polymorphic classes must create, manage, and provide their own instances to the outside world. Readers reading this article, you can refer to the author of the "Java and Mode" (just published by the electronic Industry Press) in the relevant chapters.
Introduction to a real project
This is part of a real-world Wall Street finance website project for consumers worldwide. According to the project plan, the Web site system is database driven and supports 19 different languages, and more languages will be supported in the future. Consumers can choose the language they need when they log on to the system, and the system converts the static text and dynamic text of the website to the language of the user's choice according to the user's choice.
After discussion, the designers agreed to take a different approach to static text and dynamic text:
All the pages to the translation of the static text to translate the above, and the dynamic content on the Web page needs to be solved by the program.
After the research, the designers found that they need to solve the dynamic text of the "translation" problem, in fact, some static or semi static data in the database to "translate". The following is a typical data table:
| Currency Code |
Currency name |
Monetary Mantissa |
| USD |
America (United States of America), dollars |
2 |
| CNY |
Renminbi, Yuan |
2 |
| EUR |
France, Euro |
2 |
| JPY |
Japan, Yen |
0 |
Code Listing 1, a list of currencies prepared for English users.
The currency code is always the English code seen above, but the currency name should vary according to the language the user chooses. For example, the Chinese reader should be translated into the following table:
| Currency Code |
Currency name |
Monetary Mantissa |
| USD |
United States of America (United States of America) |
2 |
| CNY |
China, RMB yuan |
2 |
| EUR |
France, Euro |
2 |
| JPY |
Japan, Japanese yen |
0 |
Code Listing 2, a list of currencies prepared for Chinese users.
Such a table appears as a Drop-down menu on a Web page, where the user sees the currency name, and the currency code is used inside the system.