Object oriented programming and interfaces
Daniel Kozak
kozzi11 at gmail.com
Tue Dec 5 08:08:55 UTC 2017
You can do something like this:
interface Medoid(T) {
float distance( T other );
uint id() const @property;
}
class Item : Medoid!(Item) {
float distance( Item m ) { return 0.;}
uint id() const @property { return 1; }
}
class MedoidClassification {
this(T:Medoid!T)(T[] list) {}
//Medoid[][] getClusters() {...}
}
void main() {
auto items = new Item[10];
auto mc = new MedoidClassification( items );
}
On Tue, Dec 5, 2017 at 8:47 AM, Dirk via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:
> 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).
>
> 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.
>
> My current approach is this (which does not work):
>
> interface Medoid {
> float distance( Medoid other );
> uint id() const @property;
> }
>
> class Item : Medoid {
> float distance( Item m ) {...}
> uint id() const @property {...}
> }
>
> class MedoidClassification {
> this( Medoid[] list ) {...}
> Medoid[][] getClusters() {...}
> }
>
> void main() {
> Item[10] items;
> auto mc = MedoidClassification( items );
> }
>
>
> What would be a good way to implement this?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20171205/10a39072/attachment-0001.html>
More information about the Digitalmars-d-learn
mailing list