So in java the way to initialise an interface, such as a collection or list, is to create an instance of a class that implements it, eg:
Collection<Object> moo = new ArrayList();
If I wanted to specify an implementation at a later time in my code, I was thinking of doing this by creating another class like:
class ListList extends ArrayList{
}
and then initialise the variable with
Collection<Object> moo = new ListList();
And then all that’s required if I want to change the implementation later on is to change what ListList extends.
So, here’s the question.. is there a better way of doing this (I still feel as though I’m inexperienced with this type of thing).
Yes: use a factory method:
Then, invoke the factory rather than instantiating:
Your suggestion of using a “dummy” subclass might appear attractive, but such abuses of inheritance invariably lead to pain and suffering later on. You really don’t want to do that.