Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-9488

Usage of factory method or Builder pattern for Locale object creation and usage.

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: 16.11.03
    • Fix Version/s: Upcoming Release
    • Component/s: framework
    • Labels:
      None

      Description

      Usage of factory method or Builder pattern for Locale object creation and usage.

      Locale aLocale = Locale.forLanguageTag("en-US");
      Locale bLocale = new Locale.Builder().setLanguage("en").setRegion("US").build();

      https://docs.oracle.com/javase/tutorial/i18n/locale/index.html

      There are many instances on which new Locale() is used instead of this we can use UtilMisc.ensureLocale()

      1. OFBIZ-9488.patch
        1 kB
        Pradhan Yash Sharma
      2. OFBIZ-9488.patch
        2 kB
        Pradhan Yash Sharma

        Activity

        Hide
        PradhanYashSharma Pradhan Yash Sharma added a comment - - edited

        Patch Available

        Show
        PradhanYashSharma Pradhan Yash Sharma added a comment - - edited Patch Available
        Hide
        PradhanYashSharma Pradhan Yash Sharma added a comment -

        Here is the updated patch.

        Show
        PradhanYashSharma Pradhan Yash Sharma added a comment - Here is the updated patch.
        Hide
        deepak.dixit Deepak Dixit added a comment -

        Thanks Yash Sharma for your contribution,

        Your patch has been committed at ofbiz-framework trunk at r#1812350

        Show
        deepak.dixit Deepak Dixit added a comment - Thanks Yash Sharma for your contribution, Your patch has been committed at ofbiz-framework trunk at r#1812350
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Hi Yash, Deepak,

        What is the advantage of using a Builder over a Constructor to create a locale? I see none reading the Creating a Locale section. I even find Constructors easier, maybe for readability?

        Show
        jacques.le.roux Jacques Le Roux added a comment - Hi Yash, Deepak, What is the advantage of using a Builder over a Constructor to create a locale? I see none reading the Creating a Locale section. I even find Constructors easier, maybe for readability?
        Hide
        PradhanYashSharma Pradhan Yash Sharma added a comment -

        Hello Jacques,

        The Java Programming language contains internationalization support for language tags, language tag filtering, and language tag lookup. These features are specified by IETF BCP 47. A builder is used to build instances of Locale from values configured by the setters. Unlike the Locale constructors, the Builder checks if a value configured by a setter satisfies the syntax requirements defined by the Locale class. A Locale object created by a Builder is well-formed and can be transformed to a well-formed IETF BCP 47 language tag without losing information.
        Please refer this link for more detail https://docs.oracle.com/javase/7/docs/api/java/util/Locale.Builder.html.
        I've also created a sub ticket for implementing the same. Thanks for raising this concern it will help others also.

        Show
        PradhanYashSharma Pradhan Yash Sharma added a comment - Hello Jacques, The Java Programming language contains internationalization support for language tags, language tag filtering, and language tag lookup. These features are specified by IETF BCP 47. A builder is used to build instances of Locale from values configured by the setters. Unlike the Locale constructors, the Builder checks if a value configured by a setter satisfies the syntax requirements defined by the Locale class. A Locale object created by a Builder is well-formed and can be transformed to a well-formed IETF BCP 47 language tag without losing information. Please refer this link for more detail https://docs.oracle.com/javase/7/docs/api/java/util/Locale.Builder.html . I've also created a sub ticket for implementing the same. Thanks for raising this concern it will help others also.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Thanks Yash,

        It's quite clear now

        Show
        jacques.le.roux Jacques Le Roux added a comment - Thanks Yash, It's quite clear now

          People

          • Assignee:
            deepak.dixit Deepak Dixit
            Reporter:
            PradhanYashSharma Pradhan Yash Sharma
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development