Hi Steven,
I don't know what's the best practice but I'll give you my quick thoughts.

It seems you have to implement some sort of logic (choosing the right name).
The main question is where is the best place to put this kind of logic?

IMO this kind of problems are solved using the "decorator pattern".
In the given example I'd choose to create "decorator" class for the
Product class

public class LocaleAwareProduct extends Product {
    private Locale locale;
    private String displayName;

    private LocaleAwareProduct() {
         // hide the default constructor
    }

    private LocaleAwareProduct(Produt aProduct, Locale aLocale) {
        this.locale = aLocale;
        if ( "en".equalsIgnoreCase(aLocale.getLanguage()) ) {
             this.displayName = aProduct.englissh_name;
        } else {
            if ( "fr".equalsIgnoreCase(aLocale.getLanguage()) ) {
                 this.displayName = aProduct.french_name;
            }
        {
    }
}

Wrapping "products" into "locale aware products" will enable you to
fetch the display name of a product without implementing the logic
into the "view component".

NOTE: the Java code has been typed in text editor and have never been
compiled so it might be buggy.

Regards,
Dimitar Vlasev

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to