8

Hey guys and girls, quick question.
Im currently writing my own collection-framework in Go.
It has a Collection-Interface, that looks like this:
Clear()
Size() int
ToSlice() []interface{}
Add(...interface{}) error
Remove(...interface{}) error
Contains(...interface{}) (bool, error)

The library should also contains stuff like stacks and queues, so datastructures, that dont fit that interface perfectly.

So should i write a weird implementation of the interface for them, like Remove for stacks (high pitched internal screaming), or should i just say fuck it, and dont implement the Collection-Interface for these specific types ?

Comments
  • 1
    I'd say you should create multiple interfaces.
  • 1
    @filthyranter
    Every data-structure already has its own interface, since I've written different implementations for each of them.
    The collection-interface was just, so that they are easily exchangeable,
    So pretty much like in java.
  • 1
    @metamourge Yeah, but the collection interface maybe only applies to all collections that can actually implement everything without weirdness.
Add Comment