Interface question

Tue Aug 29 08:46:04 PDT 2006

Charles D Hixson wrote:
> How should I write some code that would have an effect similar to what:
> interface P
> {  this(ulong ndx);
>    ulong   fset();
> }
> would have if it were a legal construct?
> The "constructor" needs to return an instance of the class that 
> implements it.

It strikes me as odd that you would want to do this. (I would have to 
see the usage though before I would say you shouldn't.) As I understand 
it the intention of Interfaces is that the underlying implementation is 
/totally/ hidden. If there is some action that the class needs to do at 
instancing time, then that should be apparent to the person coding the 
class and done by them.

OTOH, if the "this" function is doing something like registering the 
class with some sort of global catalog, you might have need for 
something like that. However I would make the registration action 
associated with the catalog and not the Objects

Objects implementing P must register with the Catalog
interface P
{  this(ulong);
    ulong   fset();

class Catalog
	void Add(P);
	void Remove(P);

Catalog cat;

class PO : P
	ulong fset(){...}

	this(ulong f)



	// OR

		ALWAYS registrar this class with the Catalog

More information about the Digitalmars-d-learn mailing list