Saturday, 17 August 2013

Storing multiple object types in a List

Storing multiple object types in a List

I have following homework about computer store:
There are several class include: Monitor, Case, Mouse, Keyboard.
All the classes have common fields: id, name, price, quantity.
Each class has some unique fields. All most features are: add, update,
delete, find, show list, save, load file
-So, first I will create a class named Product have 4 common fields. Above
classes will extends from Product.
-Then, I think I maybe create a ComputerStore class which have a field is
items type ArrayList. items stores all objects which are instance of 4
above classes But I'm not sure.
Whether it is reasonable? I need some ideas
Before , I always use ArrayList store for only one class like
List list = new ArrayList();. Now they are multi type. I think it's
generic in Java, right??

No comments:

Post a Comment