The best solution goes like this:
Better to define two objects(in Perl, actually two mudules):
- one object for item, has at least two methods:
- one method to create it from query results, not being directly called, but called by the constructor of the second class.
- One method to display
- one object for list of items (this one contains a list/array/hash (your choice) of object of the first class as its attribute), has at least four methods defined:
- one method to add memeber
- one method to delete member
- one method to display all member elements (which are objects of the first class). This calls the display method of the first class for each member
- a method to create the list from a query (after it gets the query result, then call the constructor of the first class, to form each of its member element, and also call its own add method to append each member).