| < Day Day Up > |
14.3. The Third Store
After Tim and I delivered to Sam the release containing the changes
"The second store has been successful, so I'm thinking about expanding into either Canada or Mexico. How much of an effort will be required to make that change?" "Are you talking Cozumel?" I asked. "Well, I was thinking about that or Whistler. It'd be tough to have to go on a business trip to check out how the stores were doing," he replied. "I think these systems will need a developer to install them," I stated.
"Only if it comes out of your pocketbook," he
14.3.1. Currency FlexibilityIf Sam picks Whistler (in British Columbia), Tim and I will not have to worry about translating the program into another language. We might even get away without any changes, since Canadians use dollars, albeit different ones from the U.S.
For an initial examination, we
Tim and I change the Dollar class into a Money class. That adjustment should provide the limberness to adapt to either of the proposed expansion locations. We start by creating a single class that parallels the Dollar class:
enumeration CurrencyID
{US_DOLLARS, CANADIAN_DOLLARS, MEXICAN_PESO}
class Money
CurrencyID id
Money(CurrencyID id)
// Same operations and attributes as for Dollar.
Currencies
Sam's systems
Tim and I started by making up identifiers for the individual currencies. Since currencies are universal, we did a quick search on Google? to see if a standard set of identifiers exists. We found the ISO 4217 set of currency identifiers. So the enumeration changes to this:
enumeration CurrencyID {USD, CAD,MXN}
At the same time, we found a
Currency
class for Java. Since we
Now all we need to do is to substitute Money for Dollar everywhere we find Dollar in the current system. Then we try the system using tests for Money that parallel the Dollar tests.
If we had started our design by dealing with
Money
in the beginning, we might have been bogged down in the details of exchange rates and so forth. Since Sam's systems were being used in only one country, we coded for that currency only. Creating a more generalized
You might find
14.3.2. Language Flexibility
With multiple
String ERROR_CD_DISC_NOT_IN_COLLECTION =
"CDDisc PhysicalID not in collection";.
There are at least two approaches to coding additional languages. This is another example of "The Spreadsheet Conundrum." We could provide translations of the strings in each class. A call to a configuration parameter could tell which strings to display. The pseudocode for retrieving strings would look like this: CommonString error_string = get_string(CD_DISC_NOT_IN_COLLECTION); The method would look like this:
enumeration StringID {
CD_DISC_NOT_IN_COLLECTION,
CUSTOMER_NOT_IN_COLLECTION};
CommonString get_error_string (StringID which_string)
{
static CommonStrings strings [][NUMBER_LANGUAGES] =
{"English CD Not..", "French CD Not..", "Spanish CD Not..."},
{"English Customer Not...", "French Customer Not ..",
"Spanish Customer Not..."};
index = Configuration.get_index_for_current_language( );
return strings[which_string][index]
}
Another way to handle multiple languages is to create resource files. Each resource file contains all the strings for the entire program for one language . When the program is loaded, the resource file specified by the configuration is also loaded.
Most systems are developed using the resource file approach. From a translation standpoint, having a single file containing the content to be translated is much easier than having multiple files. However, every resource file will need to be
Unfortunately, many integrated development environments (IDEs) do not support multiple languages directly. In the Java implementation in Chapter 8, the IDE places strings directly into the code. To support multiple languages, we can alter the IDE-generated code to refer to a variable that represents the string.
Language is not the only thing that changes between countries. For example, the date format changes. With a single change in a configuration file, we would like to have everything change for us. The manner in which information is displayed is separate from the decision of what to display ("Separate Concerns to Make Smaller Concerns "). Many languages and operating systems support the concept of locale, so we
|
| < Day Day Up > |