Object oriented programming and interfaces

2017-12-04 Thread Dirk via Digitalmars-d-learn
Hi! I defined an interface: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @property {...} } The compiler says: Error: class Item inte

Re: Object oriented programming and interfaces

2017-12-04 Thread Craig Dillabaugh via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! I defined an interface: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @pr

Re: Object oriented programming and interfaces

2017-12-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @property {...} } The compiler s

Re: Object oriented programming and interfaces

2017-12-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-12-04 21:43, Dirk wrote: Hi! I defined an interface: interface Medoid {     float distance( Medoid other );     uint id() const @property; } and a class implementing that interface: class Item : Medoid {     float distance( Item i ) {...}     uint id() const @property {...} } The

Re: Object oriented programming and interfaces

2017-12-04 Thread A Guy With a Question via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! float distance( Medoid other ); float distance( Item i ) {...} The two signatures need to be the same. I think this is true of most OOP languages. Have them both be: float distance( Medoid other );

Re: Object oriented programming and interfaces

2017-12-04 Thread Dirk via Digitalmars-d-learn
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

Re: Object oriented programming and interfaces

2017-12-05 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 07:47:32 UTC, Dirk wrote: What would be a good way to implement this? Did you tried to use introspection?

Re: Object oriented programming and interfaces

2017-12-05 Thread Daniel Kozak via Digitalmars-d-learn
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)

Re: Object oriented programming and interfaces

2017-12-05 Thread bauss via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 08:08:55 UTC, Daniel Kozak wrote: 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

Re: Object oriented programming and interfaces

2017-12-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 07:47:32 UTC, Dirk 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). Just don't put it in the interface. Leave it in the individual classes with the strict

Re: Object oriented programming and interfaces

2017-12-05 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! I defined an interface: interface Medoid { float distance( Medoid other ); uint id() const @property; } and a class implementing that interface: class Item : Medoid { float distance( Item i ) {...} uint id() const @pr

Re: Object oriented programming and interfaces

2017-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/4/17 3:43 PM, Dirk wrote: Hi! I defined an interface: interface Medoid {     float distance( Medoid other );     uint id() const @property; } and a class implementing that interface: class Item : Medoid {     float distance( Item i ) {...}     uint id() const @property {...} } The