How to make below code more readable and efficient? Code below reads static variables from ProductConfiguration class. Functions setAccess and setMarketAccess in two classes ProductInitialization and ProductMarketInitialization reads variables from ProductConfiguration. Can this reading be done in a better way? I still want to have file ProductConfiguration to hold public variables. Was just wondering if there is a better way of reading this variables in the other two classes, may be there in future there will be additional classes that will read variables from ProductConfiguration

public class ProductConfiguration{

      public static final PRODUCT_ACCESS=//this value is read from properties file

      public static final MARKET_PRODUCT_ACCESS=//this value is read from properties file

}


public class ProductInitialization{
    public Product setAccess(Product p){
         if(p.brand == "LOCAL") {                
             p.access=ProductConfiguration.PRODUCT_ACCESS;
             return p;
          }
         p.access = "DEFAULT";
        return p;
    }
}

public class ProductMarketInitialization{
       public void setMarketAccess(Product p){
            if(p.type == "MARKET"){               
                p.access=
              ProductConfiguration.MARKET_PRODUCT_ACCESS;
              return p;
            }
           p.access ="MARKET_DEFAULT";
          return p;
      }
}
I cannot imagine the code being that reduced; you probably removed extraneous code.
The code shown should be clearer as:

public class ProductInitialization {
    public void setAccess(Product p){
        p.access = p.brand.equals("LOCAL") ? ProductConfiguration.PRODUCT_ACCESS
             : "DEFAULT";
    }
}

public class ProductMarketInitialization {
    public void setMarketAccess(Product p){
        p.access = p.type.equals("MARKET") ? ProductConfiguration.MARKET_PRODUCT_ACCESS
                   : "MARKET_DEFAULT";
     }
}


The ProductConfiguration is taken from a properties file. This PropertiesResourceBundle is principally partly lazy. A ListResourceBundle would be totally immediate, as this is a java class containing arrays. If on the other hand you would like the startup as smoothly as possible, a totally lazy loading would need getters for the ProductConfiguration.

This seems still not very important, so be it.

The special cases of a brand LOCAL and type MARKET, and finally a special result DEFAULT and MARKET_DEFAULT hinting at yet another case handling are more cumbersome.

Old      New

LOCAL    ${productConf.productAccess}
other    Optional.empty()

MARKET   ${productConf.marketProductAccess}
other    Optional.empty()


So making the access field an Optional&lt;...&gt;, maybe even an optional getter.

Having two initialisation classes seems overdesigned, especially as they create two distinct categories of the same Product.

In general it seems too early to pay too much attention to adding extra code for nicety's sake.

    public void configAccessForDefault(Product p){
        p.access = p.brand.equals("LOCAL") ? ProductConfiguration.PRODUCT_ACCESS
             : "DEFAULT";
    }

    public void configAccessForMarket(Product p){
           p.access = p.type.equals("MARKET") ? ProductConfiguration.MARKET_PRODUCT_ACCESS
                   : "MARKET_DEFAULT";
     }