www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - extends and implements

reply %u <null devnull.com> writes:
Hello.

I know D isn't Java, but one trivial thing I liked about Java is
the introduction of 'extends' and 'implements' as keywords as ways
to clarify the class relationships when defining a class.  You
know:

class Subclass extends SuperClass implements AnInterface {
...
}

Will they ever add this in to D?  If not, why not?

thanks.
Nov 07 2011
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 07 Nov 2011 13:22:07 -0500, %u <null devnull.com> wrote:

 Hello.

 I know D isn't Java, but one trivial thing I liked about Java is
 the introduction of 'extends' and 'implements' as keywords as ways
 to clarify the class relationships when defining a class.  You
 know:

 class Subclass extends SuperClass implements AnInterface {
 ...
 }

 Will they ever add this in to D?
No.
 If not, why not?
In order for such a humongously code-breaking change to occur, there would have to be dire reasons why this was necessary. Because you liked Java is not a qualifying reason. -Steve
Nov 07 2011
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
If you need some kind of textual information on whether its a class or
an interface, you can name your interfaces with an "I".

interface IShape
{
}

abstract class Drawable
{
}

class Rectangle : IShape, Drawable {}

It's pretty common in other languages, I've seen it used in D as well.
Nov 07 2011
next sibling parent reply Justin Whear <justin economicmodeling.com> writes:
You can do this and/or use the convention of extends first, implements 
second:

class Rectangle : Drawable, IShape, IOtherInterface {}

If you're really concerned about clarity, use comments:

class Rectangle : /* extends */ Drawable,
	      /* implements */ IShape
{
}


Andrej Mitrovic wrote:

 If you need some kind of textual information on whether its a class or
 an interface, you can name your interfaces with an "I".
 
 interface IShape
 {
 }
 
 abstract class Drawable
 {
 }
 
 class Rectangle : IShape, Drawable {}
 
 It's pretty common in other languages, I've seen it used in D as well.
Nov 07 2011
parent Trass3r <un known.com> writes:
 You can do this and/or use the convention of extends first, implements
 second:

 class Rectangle : Drawable, IShape, IOtherInterface {}
It's not a convention, the spec demands that. http://d-programming-language.org/class.html
 If you're really concerned about clarity, use comments:

 class Rectangle : /* extends */ Drawable,
 	      /* implements */ IShape
 {
 }
Good point.
Nov 07 2011
prev sibling parent reply Dejan Lekic <dejan.lekic gmail.com> writes:
Andrej Mitrovic wrote:

 class Rectangle : IShape, Drawable {}
 
 It's pretty common in other languages, I've seen it used in D as well.
I used the same naming convention for interfaces until I saw this presentation: http://www.infoq.com/presentations/It-Is-Possible-to-Do-OOP- in-Java (jump to 0:42 if you do not want to see this brilliant presentation). In short there is an interface RecentlyUsedList, and Kevin recommends that good name for implementation is something like ArrayBasedRecentlyUsedList. And he is also against IRecentlyUsedList names... I actually agree with what he suggests, and stopped using INames for interfaces. :) PS. the presentation is not Java advocacy, it contains lots of Java criticism...
Nov 07 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-11-07 20:36, Dejan Lekic wrote:
 Andrej Mitrovic wrote:

 class Rectangle : IShape, Drawable {}

 It's pretty common in other languages, I've seen it used in D as well.
I used the same naming convention for interfaces until I saw this presentation: http://www.infoq.com/presentations/It-Is-Possible-to-Do-OOP- in-Java (jump to 0:42 if you do not want to see this brilliant presentation). In short there is an interface RecentlyUsedList, and Kevin recommends that good name for implementation is something like ArrayBasedRecentlyUsedList. And he is also against IRecentlyUsedList names... I actually agree with what he suggests, and stopped using INames for interfaces. :) PS. the presentation is not Java advocacy, it contains lots of Java criticism...
If the interfaces are the primary API, not implementation specific classes, then the interfaces should not be have a ugly ma,e qualify them with "I" or similar. If there is a need to separate the class and interface names then choose the ugly name of the implementation classes. -- /Jacob Carlborg
Nov 07 2011
prev sibling parent reply %u <null dddd.com> writes:
== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s article
 On Mon, 07 Nov 2011 13:22:07 -0500, %u <null devnull.com> wrote:
 In order for such a humongously code-breaking change to occur,
there would
 have to be dire reasons why this was necessary.  Because you
liked Java is
 not a qualifying reason.
 -Steve
Hey man, Sorry if I annoyed you. No need to feel insulted. I get it: the *real* reason is that it will break alot of code. I'm just asking, it's not a big deal. I find that it helps readability. But as others have stated, you list the the extended class first and that's good enough! thanks.
Nov 07 2011
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 07 Nov 2011 14:07:56 -0500, %u <null dddd.com> wrote:

 == Quote from Steven Schveighoffer (schveiguy yahoo.com)'s article
 On Mon, 07 Nov 2011 13:22:07 -0500, %u <null devnull.com> wrote:
 In order for such a humongously code-breaking change to occur,
there would
 have to be dire reasons why this was necessary.  Because you
liked Java is
 not a qualifying reason.
 -Steve
Hey man, Sorry if I annoyed you. No need to feel insulted. I get it: the *real* reason is that it will break alot of code. I'm just asking, it's not a big deal. I find that it helps readability. But as others have stated, you list the the extended class first and that's good enough!
The Internet is not always conducive to the emotional interpretation of words. Sorry if I sounded annoyed/insulted. I simply was identifying that you asked for a change that would break almost all code, and your reason was because you "liked it." I'm not annoyed, but I wanted you to understand what you were asking for and what appears to be your reason. We would need more -- a lot more. That being said, even if there was a really good reason (maybe there is, I don't know), the bar for changing something so common in the syntax has to be set very very high. It may be something we can't change even if it's for a good reason. -Steve
Nov 07 2011
prev sibling next sibling parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 07-11-2011 19:22, %u wrote:
 Hello.

 I know D isn't Java, but one trivial thing I liked about Java is
 the introduction of 'extends' and 'implements' as keywords as ways
 to clarify the class relationships when defining a class.  You
 know:

 class Subclass extends SuperClass implements AnInterface {
 ...
 }

 Will they ever add this in to D?  If not, why not?

 thanks.
Programming isn't natural language (or some variation thereof). I don't see what's wrong with using ':' for this. It's clear what it does, and not ambiguous in any way. - Alex
Nov 07 2011
prev sibling parent reply Jesse Phillips <jessekphillips+d gmail.com> writes:
On Mon, 07 Nov 2011 18:22:07 +0000, %u wrote:

 Hello.
 
 I know D isn't Java, but one trivial thing I liked about Java is the
 introduction of 'extends' and 'implements' as keywords as ways to
 clarify the class relationships when defining a class.  You know:
 
 class Subclass extends SuperClass implements AnInterface {
 ...
 }
 
 Will they ever add this in to D?  If not, why not?
 
 thanks.
There are only two instances I like know if something is an interface or class. The first is when I am defining it, for some reason I want to tell the whole world, "Hey I'm building an interface here so be sure to include these." Which really isn't important. The second is when I want to find its definition. Hmmm, should I be greping for /class Window/, /interface Window/, or /struct Window/ Otherwise the distinction has been pointless.
Nov 07 2011
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-11-08 03:07, Jesse Phillips wrote:
 On Mon, 07 Nov 2011 18:22:07 +0000, %u wrote:

 Hello.

 I know D isn't Java, but one trivial thing I liked about Java is the
 introduction of 'extends' and 'implements' as keywords as ways to
 clarify the class relationships when defining a class.  You know:

 class Subclass extends SuperClass implements AnInterface {
 ...
 }

 Will they ever add this in to D?  If not, why not?

 thanks.
There are only two instances I like know if something is an interface or class. The first is when I am defining it, for some reason I want to tell the whole world, "Hey I'm building an interface here so be sure to include these." Which really isn't important. The second is when I want to find its definition. Hmmm, should I be greping for /class Window/, /interface Window/, or /struct Window/ Otherwise the distinction has been pointless.
This should be handled by an IDE/editor with go-to-definition. -- /Jacob Carlborg
Nov 07 2011
prev sibling parent Kagamin <spam here.lot> writes:
Jesse Phillips Wrote:

 The second is when I want to find its definition. Hmmm, should I be 
 greping for /class Window/, /interface Window/, or /struct Window/
[a-z]* Window ?
Nov 08 2011