The sort.Interface is designed to operate on an indexed collection. 
Certain data structures may not be indexed (ex. linked list) nor do some 
algorithms need to expose that they are.

Lets say I have one package with the following interface.

package One

type Item interface {
    Less(item Item) bool
}

If say *for some reason* it made sense to want to use package One's Item in 
package Two, but package Two already had an Item interface declared. 
I would need to first import package One and explicitly prefix all uses of 
Item to differentiate between the packages.

package Two

import "path/to/package/One" // ignoring the use of '.' notation to import 
package block

// lets say this package has its own Item declared
type Item interface {
    Len() int
    Less(item Item) bool
    Swap(item Item)
}

// lets also assume that Two.Item would not be appropriate for this function
func SomeOperation(a,b One.Item) bool {
    ...
}

Furthermore the concrete Item will need to cast/assert the type for the 
passed in argument.

package Two

import "path/to/package/One"

type TwoItem int
func (this TwoItem) Less(item One.Item) {
    return this < item.(TwoItem)
}


Is there a cleaner more elegant way to setup *this given* relationship? One 
maybe that isn't as verbose (ex. share a single interface) and avoid the 
casting?
I presume, that the proper convention would be to not share the interface 
but I want to get an idea of other patterns that could be applied here.




-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to