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

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 16.11.01
    • Fix Version/s: 16.11.01
    • Component/s: ALL COMPONENTS
    • Labels:
      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.

        Activity

        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        +1

        Show
        jacques.le.roux Jacques Le Roux added a comment - +1
        Hide
        pandeypranay Pranay Pandey added a comment -

        +1

        Show
        pandeypranay Pranay Pandey added a comment - +1
        Hide
        arunpati Arun Patidar added a comment -

        All sub-tasks has been closed. Now closing this ticket.

        Thanks Divesh Dutta, Amit Gadaley and Shubham Agrawal for the contribution.

        Show
        arunpati Arun Patidar added a comment - All sub-tasks has been closed. Now closing this ticket. Thanks Divesh Dutta , Amit Gadaley and Shubham Agrawal for the contribution.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development