I have an interface TestInterface and different classes may implement the interface. Is it possible to have a collection of all the objects which implements the interface? The collection can be created using
LinkedList<TestInterface> store
where store is the name of the collection. But how to keep track of the object creations of classes which implement the TestInterface. And moreover where to keep the collection?
Not knowing what you want this for, it’s hard to tell.
But anyway, yes you can create a collection but in order to track and store references to the
TestInterfaceobjects, you must control their creation.The easiest way would be to have a
TestInterfaceFactory(see AbstractFactory pattern), this is also a good place to keep thestorecollection with the instance references.