<div dir="ltr"><div>You can do something like this:</div><div><br></div><div>interface Medoid(T) {</div><div>    float distance( T other );</div><div>    uint id() const @property;</div><div>}</div><div><br></div><div>class Item : Medoid!(Item) {</div><div>    float distance( Item m ) { return 0.;}</div><div>    uint id() const @property { return 1; }</div><div>}</div><div><br></div><div>class MedoidClassification {</div><div>    this(T:Medoid!T)(T[] list) {}</div><div>    //Medoid[][] getClusters() {...}</div><div>}</div><div><br></div><div>void main() {</div><div>    auto items = new Item[10];</div><div>    auto mc = new MedoidClassification( items );</div><div>}</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 5, 2017 at 8:47 AM, Dirk via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The distance function is implementation dependend and can only be computed between two objects of the same class (in this example the class is Item).<br>
<br>
My goal is to write a module for a k-medoids clustering algorithm. The class MedoidClassification shall be able to partition a list of objects from the same class, which implement the Medoid interface.<br>
<br>
My current approach is this (which does not work):<br>
<br>
interface Medoid {<span class=""><br>
    float distance( Medoid other );<br></span>
    uint id() const @property;<br>
}<br>
<br>
class Item : Medoid {<br>
    float distance( Item m ) {...}<span class=""><br>
    uint id() const @property {...}<br>
}<br>
<br></span>
class MedoidClassification {<br>
    this( Medoid[] list ) {...}<br>
    Medoid[][] getClusters() {...}<br>
}<br>
<br>
void main() {<br>
    Item[10] items;<br>
    auto mc = MedoidClassification( items );<br>
}<br>
<br>
<br>
What would be a good way to implement this?<br>
</blockquote></div><br></div>