LOGICO
January 16th, 2006, 04:22 PM
A program needs to set and keep track of Vans wich are free and vans wich are occupied doing some delivery.
It's necessary to know the state of a van so we can show all the vans and what they are doing. It's also necessary that the program can show the list of those who are delivering.
A couple of options for the data structures to hold the information:
FIRST
* ListOfFreeVans
* ProductList
* Work = Van + ProductList
* ListOfWork = all the Vans and the products they are delivering
when a van goes deliver a product (or more) it is removed from the ListOfFreeVans and a Work object is created that uses that van and a List of Products.
PROS:
- almost direct display of Vans that are occupied (Works[i].getVan () )
CONS:
- To show all the vans it's necessary to loop the ListOfFreeVans and the ListOfWork getting the van from each work.
- It inserts and removes Vans from each list when they change their state
SECOND
* ListOfVans - all vans
This list has a field called DELIEVRING that's either null of a reference to a ProductList
* ProductList
Example
[Van Code][delivery]
[Van1][null]
[Van2][xxxx]
To show all vans we just loop the ListOfVans and show the van.
PROS:
- easy to display the full list
- doesn't need inserts and removes to swap lists, just logic to change the value of "delivery"
- ...
CONS:
- need to parse the full list to show the occupied ones.
Any comments on these and other solutions are welcome. Thanks.
It's necessary to know the state of a van so we can show all the vans and what they are doing. It's also necessary that the program can show the list of those who are delivering.
A couple of options for the data structures to hold the information:
FIRST
* ListOfFreeVans
* ProductList
* Work = Van + ProductList
* ListOfWork = all the Vans and the products they are delivering
when a van goes deliver a product (or more) it is removed from the ListOfFreeVans and a Work object is created that uses that van and a List of Products.
PROS:
- almost direct display of Vans that are occupied (Works[i].getVan () )
CONS:
- To show all the vans it's necessary to loop the ListOfFreeVans and the ListOfWork getting the van from each work.
- It inserts and removes Vans from each list when they change their state
SECOND
* ListOfVans - all vans
This list has a field called DELIEVRING that's either null of a reference to a ProductList
* ProductList
Example
[Van Code][delivery]
[Van1][null]
[Van2][xxxx]
To show all vans we just loop the ListOfVans and show the van.
PROS:
- easy to display the full list
- doesn't need inserts and removes to swap lists, just logic to change the value of "delivery"
- ...
CONS:
- need to parse the full list to show the occupied ones.
Any comments on these and other solutions are welcome. Thanks.