Click to See Complete Forum and Search --> : ADT - Identifying types


LOGICO
December 28th, 2005, 08:52 AM
Hello,
I'm not sure what is considered a "type". I need to identify the several types within a problem.

Example:
"There are products (name and code) and vans (brand and code) A van take a product to X. Vans are atributed to products by order of arrival. "

Now the "easy to identify" types are:

PRODUCT
VAN

However there will need to be a way to keep the information that a van is taking some product.

In implementation this could be a Lisp List like (van_object product_object). Let's call this a "WorkList". Is this a "type"?
Are those kind of "containers" normally types? If I need to keep a list of Vans for, is that a type?

Thanks.

Hnefi
December 28th, 2005, 12:20 PM
Yes, in your example, WorkList would be considered a type. Usually in Lisp however, types are implemented as a punctuated list looking like this: (TypeName . Contents). In your example, that would mean that WorkList would look like (WorkList . (Van_Object Product_Object)). This is only a convention - you can have types looking like whatever you want - but having the type include an identifier means that it is much easier to write functions that manipulate only the desired types. One typical function that would be written for WorkList might be Unload(WorkList).

Of course, if Van_Object already is a container, there is no need for the WorkList type. This is a typical dilemma - there is no clearcut way to determine what types are necessary for a problem, because most problems can be solved in many different ways.

As for your list of vans, are there any operations you would need to be able to do on that list that you can't do with a simple command on lists in general? If so, it's a good idea to let the vanlist be its own type with functions to manipulate it. Otherwise, you might as well let it be a regular list and nothing more.

LOGICO
December 29th, 2005, 12:39 PM
Thanks for your comments.


As for your list of vans, are there any operations you would need to be able to do on that list that you can't do with a simple command on lists in general? If so, it's a good idea to let the vanlist be its own type with functions to manipulate it. Otherwise, you might as well let it be a regular list and nothing more.

The lists of products will probably be a simple container. There's only one rule (the order is important so older Products can be processed first). The list of vans has no rules and we only need to be able to select, delete out and insert element.

However let's change that problem a little bit and say that a van can only take a product if it some rule applies (example: Van Capacity > Product Weight). So the program will need an operation that giving a ProductList and a Van will chose a Product that can be carried by that Van and return a "WorkList" with that Van and a Product. Or an operation that given a Van will return a WorkList with several products as long has their total weigth doesn't excede the Van capacity.

With this kind of selection logic it makes more sence that the ProductList becomes a type/ADT, correct?

Thanks.

Hnefi
December 29th, 2005, 06:53 PM
With this kind of selection logic it makes more sence that the ProductList becomes a type/ADT, correct?
Correct. For every non-trivial operation needed on the data, it makes more sense to consider it a type.