I just want to add a couple of points.
Code to the Interface instead of its Implementation:
When declaring an object you want to declare it as the highest level object needed as opposed to its specific implementation.
In this case you wrote:
ArrayList<String> open = main.getOpenable();
This requires that main.getOpenable()
returns an ArrayList
. What happens if in the future you decide to have it return a LinkedList
? It could break the current code.
It is a much better idea to simply do:
List<String> open = main.getOpenable();
Now you can pass it any sort of List
with no issues.
Note: Obviously you need to ensure that the interface contains all the methods you need to call, but here that is the case.
You can use a for-each loop to iterate over the List:
This may be a style choice, but it leads to cleaner code. Consider the following (using the StringBuilder
effeciency):
public void listOpen() {
ArrayList<String> open = main.getOpenable();
StringBuilder appendBuilder = new StringBuilder();
for(String value : open) {
appendBuilder.append(value).append("\n");
error.setScroll();
}
textWindow.append(appendBuilder.toString());
}
Here the benefit is small, but it does remove a line of code and removes some of the possibility of errors.