www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Not possible to just implement an interface?

reply Paul Bonser <misterpib gmail.com> writes:
Looking at the syntax for defining a class, it seems that there's no way 
to have a class simply implement an interface...
Is that right? Or do you just put the interface declaration in place of 
the superclass declaration if there is no superclass?

-- 

-PIB

--
"C++ also supports the notion of *friends*: cooperative classes that
are permitted to see each other's private parts." - Grady Booch
Jan 21 2005
next sibling parent Chris Sauls <Chris_member pathlink.com> writes:
In article <css9lq$1ek8$1 digitaldaemon.com>, Paul Bonser says...
Looking at the syntax for defining a class, it seems that there's no way 
to have a class simply implement an interface...
Is that right? Or do you just put the interface declaration in place of 
the superclass declaration if there is no superclass?
The documentation can be slightly misleading if one only looks at that syntax diagram, I'll agree. Yes you can write a class that only implements an interface. If no superclass is given in a class decleration, then DMD auto-magically makes it a child of std.object.Object and moves along. -- Chris Sauls
Jan 21 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Paul Bonser" <misterpib gmail.com> wrote in message
news:css9lq$1ek8$1 digitaldaemon.com...
 Looking at the syntax for defining a class, it seems that there's no way
 to have a class simply implement an interface...
 Is that right?
No.
 Or do you just put the interface declaration in place of
 the superclass declaration if there is no superclass?
Yes. (If no superclass is specified, it is implicitly set to "Object" anyway.)
Jan 21 2005
parent reply Paul Bonser <misterpib gmail.com> writes:
Walter wrote:
 "Paul Bonser" <misterpib gmail.com> wrote in message
 news:css9lq$1ek8$1 digitaldaemon.com...
 
Looking at the syntax for defining a class, it seems that there's no way
to have a class simply implement an interface...
Is that right?
No.
Or do you just put the interface declaration in place of
the superclass declaration if there is no superclass?
Yes. (If no superclass is specified, it is implicitly set to "Object" anyway.)
Okay, that's what I was assuming. So I may be asking all sorts of questions that are really picky like this because I am working on my own implementation of D right now (keeping the details to myself for now, hope to drop it as a pleasant surprise sometime soon). In fact, I have another question. In the enums section of the docs, the enum declaration is as follows: EnumDeclaration: enum Identifier EnumBody enum EnumBody enum identifier : EnumBaseType EnumBody enum EnumBaseType : EnumBody Why is the colon there after EnumBaseType in the last one? It seems like it's not neccesary, or am I missing the reasoning behind having it there? Also, Identifier is not capitalized in the second to last line, but I'm pretty sure that's just a typo. -- -PIB -- "C++ also supports the notion of *friends*: cooperative classes that are permitted to see each other's private parts." - Grady Booch
Jan 21 2005
parent reply Chris Sauls <Chris_member pathlink.com> writes:
In article <cssigl$1o5c$1 digitaldaemon.com>, Paul Bonser says...
In the enums section of the docs, the enum declaration is as follows:
EnumDeclaration:
	enum Identifier EnumBody
	enum EnumBody
	enum identifier : EnumBaseType EnumBody
	enum EnumBaseType : EnumBody

Why is the colon there after EnumBaseType in the last one? It seems like 
it's not neccesary, or am I missing the reasoning behind having it there?
Also, Identifier is not capitalized in the second to last line, but I'm 
pretty sure that's just a typo.
I think the colon is a typo as well. Having used that particular syntax a bit, I believe the line should be With the colon in the same place it would be were there an identifier. Example: -- Chris Sauls
Jan 21 2005
parent "Walter" <newshound digitalmars.com> writes:
That's right. I'll fix it. Thanks!
Jan 21 2005