You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "Paul Rogers (JIRA)" <ji...@apache.org> on 2018/11/19 02:40:00 UTC
[jira] [Commented] (IMPALA-7867) Expose collection interfaces, not
implementations
[ https://issues.apache.org/jira/browse/IMPALA-7867?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16691195#comment-16691195 ]
Paul Rogers commented on IMPALA-7867:
-------------------------------------
[~marcelk], thanks much for the note. The guarantees you site for {{ArrayList}} are accurate. This is why, when _creating_ a list, {{ArrayList}} is often a good choice.
However, when _declaring_ a list, the interface is sufficient. Though a variable is declared as {{List}}, its implementation is actually {{ArrayList}} if declared that way.
Not sure if this is a difference between Java and C++ behavior, but it is pretty standard Java practice to hind the implementation choice and expose only the generic interface.
Example:
{code:java}
public class Foo {
// Declaration is generic, implementation is ArrayList
private final List<Bar> myList_ = new ArrayList<>();
// Interface is generic
List<Bar> getList() { return myList_; }
// Implementation in terms of generic interface, implementation
// is O(1) as guaranteed by ArrayList.
void Bar getBar(int i) {
return myList_.get(i);
}
}
{code}
Does this clear up the confusion?
> Expose collection interfaces, not implementations
> -------------------------------------------------
>
> Key: IMPALA-7867
> URL: https://issues.apache.org/jira/browse/IMPALA-7867
> Project: IMPALA
> Issue Type: Improvement
> Components: Frontend
> Affects Versions: Impala 3.0
> Reporter: Paul Rogers
> Assignee: Paul Rogers
> Priority: Minor
>
> When using Java collections, a common Java best practice is to expose the collection interface, but hide the implementation choice. This pattern allows us to start with a generic implementation (an {{ArrayList}}, say), but evolve to a more specific implementation to achieve certain goals (a {{LinkedList}} or {{ImmutableList}}, say.)
> For whatever reason, the Impala FE code exposes {{ArrayList}}, {{HashMap}} and other implementation choices as variable types and in method signatures.
> This ticket tracks a gradual process of revising the declarations and signatures to use the interfaces {{List}} instead of the implementation {{ArrayList}}.
> Also, the FE code appears to predate Java 7, so that declarations of lists tend to be in one of two forms (with or without Guava):
> {code:java}
> foo1 = new ArrayList<Bar>();
> foo2 = Lists.newArrayList();
> {code}
> Since Java 7, the preferred form is:
> {code:java}
> foo = new ArrayList<>();
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscribe@impala.apache.org
For additional commands, e-mail: issues-all-help@impala.apache.org