hope
hope copied to clipboard
Define container behavior
Goal: swappable implementations
Some common operations for a vague notion of a container could be:
-
empty
-
add
-
remove
-
find
-
length
-
is_empty
-
is_element
These are suitable for at least: list, set, stack, queue, heap, dictionary.
Being that each implementation defines a particular order, our collection is also a sequence, so ordered access can also make sense:
-
first
-
last
-
nth
There is a semantic conflict for a remove
operation between a set and a queue/stack, since set removes a specific item and queue/stack remove whatever is at the top of the order. Can we come-up with an abstraction to accommodate both?
A heap is probably less of a problem, since it can be viewed as just an extension to the regular queue/stack interface.