You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Divesh Dutta (JIRA)" <ji...@apache.org> on 2016/06/21 07:30:58 UTC

[jira] [Created] (OFBIZ-7521) Refer to objects by their interfaces rather than class when instantiating Collection implementation classes in Java files

Divesh Dutta created OFBIZ-7521:
-----------------------------------

             Summary: Refer to objects by their interfaces rather than class when instantiating Collection implementation classes  in Java files 
                 Key: OFBIZ-7521
                 URL: https://issues.apache.org/jira/browse/OFBIZ-7521
             Project: OFBiz
          Issue Type: Improvement
          Components: ALL COMPONENTS
    Affects Versions: Upcoming Branch
            Reporter: Divesh Dutta


We should use 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: 

{code}
ArrayList<EntityCondition> itemsExprs = new ArrayList<EntityCondition>();
{code}

should be written as :

{code}
List<EntityCondition> itemsExprs = new ArrayList<EntityCondition>();
{code}

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.  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)