Java Collections includes many implementations. Therefore, itβs much easier for me to use
List<String> myList = new ArrayList<String>();
Then in the future, when I understand, I need the "myList" to be thread safe, just changing this single line to
List<String> myList = new Vector<String>();
And do not change another line of code. This also includes getters / setters. If you look at the number of implementations of the Map, for example, you can imagine why this might be good practice. In other languages, where there is only a couple of implementations for something (sorry, not a big .NET guy), but in Objective-C there really is only NSDictionary and NSMutableDictionary. So it doesnβt make much sense.
Edit:
Failed to click on one of my key points (just referenced it using getter / seters).
The above allows you to:
public void setMyList(List<String> myList) { this.myList = myList; }
And the client using this call should not worry about the underlying implementation. Using any object that matches the List interface that they can have.
MarkPowell Oct 20 '09 at 15:55 2009-10-20 15:55
source share