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

Refer to objects by their interfaces rather than class when instantiating Collection implementation classes in Java files

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Done
    • 16.11.01
    • 16.11.01
    • ALL COMPONENTS
    • None

    Description

      We should favor the use of interfaces rather than class to refer to objects where ever possible. It is entirely appropriate to refer an object by a class rather than an interface if no appropriate interface exists. But wherever appropriate interface exists we should use them to refer to objects.

      For example:

      ArrayList<EntityCondition> itemsExprs = new ArrayList<EntityCondition>();
      

      should be written as :

      List<EntityCondition> itemsExprs = new ArrayList<EntityCondition>();
      

      Writing this way will make code more flexible . If you want to switch implementations, all you have to do is change the class name in the constructor and all surrounding code will continue to work.

      This is parent ticket, we will create logical tasks for each component and collection class to improve this code. There are very less such occurrences and most of the code is written following the best practice. But we could improve the code which has not followed this best practice.

      Attachments

        Activity

          People

            arunpati Arun Patidar
            diveshdut Divesh Dutta
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: