How to store a list of Objects that might change in future?
Posted
by
Amogh Talpallikar
on Programmers
See other posts from Programmers
or by Amogh Talpallikar
Published on 2012-03-21T16:13:49Z
Indexed on
2012/03/21
17:37 UTC
Read the original article
Hit count: 237
java
|object-oriented
I have set of Objects of the same class which have different values of their attributes. and I need to find the best match from a function under given scenarios out of these objects.
In future these objects might increase as well.
Quite similar to the way we have Color class in awt. we have some static color objects in the class with diff rgb values. But in my case say, I need to chose the suitable color out of these static ones based on certain criteria.
So should I keep them in an arrayList or enum or keep them as static vars as in case of Colors. because I will need to parse through all of them and decide upon the best match. so I need them in some sort of collection. But in future if I need to add another type I will have to modify the class and add another list.add(object) call for this one and then it will violate the open-close principle. How should I go about it ?
© Programmers or respective owner