D - interfaces
- Pavel Minayev (19/19) Feb 02 2002 How do I resolve the conflict of two interfaces in D. I wrote
- Pavel Minayev (21/21) Feb 02 2002 One more thing. How to crash the compiler? Easy: =)
- Walter (4/25) Feb 02 2002 It doesn't work because the compiler's name resolution hasn't parsed the
- Pavel Minayev (3/5) Feb 02 2002 So it should give an error message? 'cause it doesn't...
- Walter (3/8) Feb 02 2002 That, then, is a bug!
- Pavel Minayev (8/8) Feb 02 2002 This works:
- Walter (4/23) Feb 02 2002 What happens is foobar.baz() becomes the baz implementation for BOTH foo...
- Pavel Minayev (4/6) Feb 02 2002 and
- Walter (3/9) Feb 02 2002 Your only option is to change the name on one of the interfaces.
- Pavel Minayev (9/10) Feb 02 2002 Aren't you going to add some way to resolve this, like in C#
- Walter (4/14) Feb 02 2002 I didn't know those languages offered that. While it's possible to imple...
- Pavel Minayev (11/13) Feb 02 2002 implement
- Paul Apostolik (12/25) Feb 03 2002 I believe Java dealt with this same problem with their package naming
- Mike Wynn (57/85) Feb 03 2002 FYI:
- Pavel Minayev (1/1) Feb 03 2002 Yet Delphi and C# do differentiate.
- Russ Lewis (10/10) Feb 04 2002 When I first looked at what you were talking about, I was with
- Pavel Minayev (4/9) Feb 04 2002 ...because matching names doesn't mean matching purposes!
- Russ Lewis (7/10) Feb 04 2002 Exactly what?
- Pavel Minayev (4/10) Feb 04 2002 we
- Russ Lewis (6/6) Feb 04 2002 I can live with that.
- OddesE (15/21) Feb 04 2002 I agree, but it can be a drag to.
- Patrick Down (6/25) Feb 03 2002 The way I see it a interface is a contract that says a class implements
-
Carlos Santander B.
(42/42)
Mar 23 2003
"Pavel Minayev"
escribiσ en el mensaje - Russ Lewis (13/48) Mar 30 2003 t why
- Matthew Wilson (20/55) Mar 30 2003 That would be the best approach. After all, the usual reason for derivin...
How do I resolve the conflict of two interfaces in D. I wrote this: interface foo { void baz(); } interface bar { void baz() } class foobar: foo, bar { void baz() { } } Now foobar is supposed to have two versions of baz() - one from foo, one from bar. But how do I implement them separately? I can just write "void baz()", and the compiler doesn't complain (why?!), but which method actually gets implemented? I tried foo.baz and bar.baz, but it doesn't work...
Feb 02 2002
One more thing. How to crash the compiler? Easy: =) class foobar: foobar.foo, foobar.bar { interface foo { void baz(); } interface bar { void baz(); } void baz() { } } I don't see anything wrong in this code. Interfaces declared inside the class don't differ from those outside, it should be pretty legal to inherit that class from them... this can be useful if you want to deal with interfaces but don't want to expose them to others. Also, when doing "class foobar: foo, bar", it complains that "identifier foo is not defined". Why? Shouldn't class know about all its members?
Feb 02 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a3g9c6$195r$1 digitaldaemon.com...One more thing. How to crash the compiler? Easy: =) class foobar: foobar.foo, foobar.bar { interface foo { void baz(); } interface bar { void baz(); } void baz() { } } I don't see anything wrong in this code. Interfaces declared inside the class don't differ from those outside, it should be pretty legal to inherit that class from them... this can be useful if you want to deal with interfaces but don't want to expose them to others.It doesn't work because the compiler's name resolution hasn't parsed the inside of the class when it is trying to resolve the outside.Also, when doing "class foobar: foo, bar", it complains that "identifier foo is not defined". Why? Shouldn't class know about all its members?
Feb 02 2002
"Walter" <walter digitalmars.com> wrote in message news:a3gbp0$1got$4 digitaldaemon.com...It doesn't work because the compiler's name resolution hasn't parsed the inside of the class when it is trying to resolve the outside.So it should give an error message? 'cause it doesn't...
Feb 02 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a3gfvi$1jia$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a3gbp0$1got$4 digitaldaemon.com...That, then, is a bug!It doesn't work because the compiler's name resolution hasn't parsed the inside of the class when it is trying to resolve the outside.So it should give an error message? 'cause it doesn't...
Feb 02 2002
This works: interface foobar: foo, bar { } This crashes the compiler: interface foobar: foo, bar; Not to mention it definitely shoudln't, I think it should be a legal declaration, useful to "group" methods together or to declare a separate interface which doesn't differ from the base one (would be useful for COM event handling).
Feb 02 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a3g93h$1944$1 digitaldaemon.com...How do I resolve the conflict of two interfaces in D. I wrote this: interface foo { void baz(); } interface bar { void baz() } class foobar: foo, bar { void baz() { } } Now foobar is supposed to have two versions of baz() - one from foo, one from bar. But how do I implement them separately? I can just write "void baz()", and the compiler doesn't complain (why?!), but which method actually gets implemented? I tried foo.baz and bar.baz, but it doesn't work...What happens is foobar.baz() becomes the baz implementation for BOTH foo and bar.
Feb 02 2002
"Walter" <walter digitalmars.com> wrote in message news:a3gbov$1got$3 digitaldaemon.com...What happens is foobar.baz() becomes the baz implementation for BOTH fooandbar.And if I need to provide separate implementations?...
Feb 02 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a3gfjr$1jb0$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a3gbov$1got$3 digitaldaemon.com...Your only option is to change the name on one of the interfaces.What happens is foobar.baz() becomes the baz implementation for BOTH fooandbar.And if I need to provide separate implementations?...
Feb 02 2002
"Walter" <walter digitalmars.com> wrote in message news:a3gh3a$1k44$2 digitaldaemon.com...Your only option is to change the name on one of the interfaces.or Delphi? Like this: class foobar: foo, bar { void foo.baz() { ... } void bar.baz() { ... } }
Feb 02 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a3gm8e$1m2f$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a3gh3a$1k44$2 digitaldaemon.com...I didn't know those languages offered that. While it's possible to implement that, is it really necessary to support it?Your only option is to change the name on one of the interfaces.or Delphi? Like this: class foobar: foo, bar { void foo.baz() { ... } void bar.baz() { ... } }
Feb 02 2002
"Walter" <walter digitalmars.com> wrote in message news:a3heol$1vvv$1 digitaldaemon.com...I didn't know those languages offered that. While it's possible toimplementthat, is it really necessary to support it?Yes. Because sometimes it's not you who define the interfaces. It might happen so that two =absolutely= different interfaces, from different vendors, have to be implemented - and they can potentially have name clashes, and you can't just change one of them that simply because it's not your code... so you need a way to different between those methods somehow. So far all languages I've seen provide the interface.method form for this.
Feb 02 2002
Pavel Minayev wrote:"Walter" <walter digitalmars.com> wrote in message news:a3heol$1vvv$1 digitaldaemon.com...I believe Java dealt with this same problem with their package naming scheme. -- Paul Apostolik paul arches.uga.edu parabolis softhome.net Command line arguments -- main( int argc, char * * argv ) { if( argc == 1 ) { cout<<"It's a nice day."<<endl; } else { cout<<"Don't argue with me, it _is_ a nice day."<<endl; } }I didn't know those languages offered that. While it's possible toimplementthat, is it really necessary to support it?Yes. Because sometimes it's not you who define the interfaces. It might happen so that two =absolutely= different interfaces, from different vendors, have to be implemented - and they can potentially have name clashes, and you can't just change one of them that simply because it's not your code... so you need a way to different between those methods somehow. So far all languages I've seen provide the interface.method form for this.
Feb 03 2002
FYI: As far as I remember, and I've checked in the VM spec, but can't find a real answer, in Java if two interfaces declare a function with the same signature (N.B. Java VM's DO overload on return value, even though the language does not support this feature) and you implement BOTH, you only implement one mehtod and calls to that method from either interface would got to the same method. so if you have interface IsRenderable { void draw(); } interface HasPension { void draw(); } class A implements IsRenderable, HasPension { void public draw() System.out.println("boo!");} } class B static void getPension(HasPension h) { h.draw(); } } class static void showObj(IsRenderable r){ r.draw(); } } class test { static void main( String[] argv ) { A a = new A(); B.getPension( a ); C.showObj( a ); } } well the jdk 1.0.2/1.1 VM did and it compiles and runs under 1.3 fine. in java an interface is just "I agree to implement a function with this signature",nothing more. and if you try interface IsRenderable { void draw(); } interface HasPension { int draw(); } class A implements IsRenderable, HasPension public void draw() { System.out.println("boo!");} public int draw() { return 1; } } class B static void getPension(HasPension h) { h.draw(); } } class static void showObj(IsRenderable r) { r.draw(); } } class test { static void main( String[] argv ) { A a = new A(); B.getPension( a ); System.out.println( "and I get $" + C.showObj( a )+" pension!" ); } } you can't do it unless you write a with in bytecode asm. you can not do implement an interface that would cause overloading of the return value Mike. "Paul Apostolik" <parabolis softhome.net> wrote in message news:3C5CF999.868FAF41 softhome.net...Pavel Minayev wrote:"Walter" <walter digitalmars.com> wrote in message news:a3heol$1vvv$1 digitaldaemon.com...I believe Java dealt with this same problem with their package naming scheme. -- Paul Apostolik paul arches.uga.edu parabolis softhome.net Command line arguments -- main( int argc, char * * argv ) { if( argc == 1 ) { cout<<"It's a nice day."<<endl; } else { cout<<"Don't argue with me, it _is_ a nice day."<<endl; } }I didn't know those languages offered that. While it's possible toimplementthat, is it really necessary to support it?Yes. Because sometimes it's not you who define the interfaces. It might happen so that two =absolutely= different interfaces, from different vendors, have to be implemented - and they can potentially have name clashes, and you can't just change one of them that simply because it's not your code... so you need a way to different between those methods somehow. So far all languages I've seen provide the interface.method form for this.
Feb 03 2002
When I first looked at what you were talking about, I was with Walter...why do you need it? However, I repent. We do need to be able to provide separate implementations. How do we define which of the baz() functions is foobar.baz()? Or do we have to call them as foobar.foo.baz() and foobar.bar.baz()??? -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Feb 04 2002
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3C5ECBF3.3270321C deming-os.org...When I first looked at what you were talking about, I was with Walter...why do you need it? However, I repent. We do need to be able to provide separate implementations....because matching names doesn't mean matching purposes!How do we define which of the baz() functions is foobar.baz()? Or do we have to call them as foobar.foo.baz() and foobar.bar.baz()???Yes, exactly.
Feb 04 2002
Pavel Minayev wrote:Exactly what? -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]How do we define which of the baz() functions is foobar.baz()? Or do we have to call them as foobar.foo.baz() and foobar.bar.baz()???Yes, exactly.
Feb 04 2002
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3C5F0184.8EFDD824 deming-os.org...Pavel Minayev wrote:weHow do we define which of the baz() functions is foobar.baz()? Or doUse the qualifier. foobar.foo.baz() or foobar.bar.baz().Exactly what?have to call them as foobar.foo.baz() and foobar.bar.baz()???Yes, exactly.
Feb 04 2002
I can live with that. -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Feb 04 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a3mpt3$1gud$1 digitaldaemon.com..."Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3C5ECBF3.3270321C deming-os.org...I agree, but it can be a drag to. If some interface inherits from another, you can't implement both of these interfaces, except if D does like it does now, assume that when two functions in different interfaces have the same name and signature they represent the same operation. It should be possible to qualify them if you want different behaviour. Possible, but not necessary! -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net __________________________________________ Remove _XYZ from my address when replying by mailWhen I first looked at what you were talking about, I was with Walter...why do you need it? However, I repent. We do need to be able to provide separate implementations....because matching names doesn't mean matching purposes!
Feb 04 2002
"Walter" <walter digitalmars.com> wrote in news:a3heol$1vvv$1 digitaldaemon.com:"Pavel Minayev" <evilone omen.ru> wrote in message news:a3gm8e$1m2f$1 digitaldaemon.com...The way I see it a interface is a contract that says a class implements a certain set of functionality. Just because two functions are named that same between two interfaces does not mean that serve that same purpose in both."Walter" <walter digitalmars.com> wrote in message news:a3gh3a$1k44$2 digitaldaemon.com...I didn't know those languages offered that. While it's possible to implement that, is it really necessary to support it?Your only option is to change the name on one of the interfaces.or Delphi? Like this: class foobar: foo, bar { void foo.baz() { ... } void bar.baz() { ... } }
Feb 03 2002
"Pavel Minayev" <evilone omen.ru> escribiσ en el mensaje news:a3gm8e$1m2f$1 digitaldaemon.com... | "Walter" <walter digitalmars.com> wrote in message | news:a3gh3a$1k44$2 digitaldaemon.com... | | > Your only option is to change the name on one of the interfaces. | | or Delphi? Like this: | | class foobar: foo, bar | { | void foo.baz() { ... } | void bar.baz() { ... } | } | Some agreed that it could be useful. I'm also for it, specially because this is illegal: interface I1 { int a(); } interface I2 { void a(); } class C:I1,I2 { void a() { return; } int a() { return 0; } } But if I could do: class C:I1,I2 { void I2.a() { return; } int I1.a() { return 0; } } Then there would be no problem. Or am I wrong? I think I am, but I don't why :D Carlos Santander | --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17
Mar 23 2003
"Carlos Santander B." wrote:"Pavel Minayev" <evilone omen.ru> escribi=F3 en el mensaje news:a3gm8e$1m2f$1 digitaldaemon.com... | "Walter" <walter digitalmars.com> wrote in message | news:a3gh3a$1k44$2 digitaldaemon.com... | | > Your only option is to change the name on one of the interfaces. | | or Delphi? Like this: | | class foobar: foo, bar | { | void foo.baz() { ... } | void bar.baz() { ... } | } | Some agreed that it could be useful. I'm also for it, specially because=thisis illegal: interface I1 { int a(); } interface I2 { void a(); } class C:I1,I2 { void a() { return; } int a() { return 0; } } But if I could do: class C:I1,I2 { void I2.a() { return; } int I1.a() { return 0; } } Then there would be no problem. Or am I wrong? I think I am, but I don'=t why:DI don't see any reason why the latter version must be illegal. However, = you should note, of course, that you would not be able to call either version= of a() directly, without a cast. -- The Villagers are Online! http://villagersonline.com =2E[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] =2E[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Mar 30 2003
That would be the best approach. After all, the usual reason for deriving from an interface is to deal polymorphically with the instances via the interface, in which guise the casts are non necessary. In fact, I can't see how the language could _not_ support this. Is that really the current state of play? If so, we'll be forced to do use intermediate classes, a la C++, which really sucks "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3E86F3FE.43B6C650 deming-os.org... "Carlos Santander B." wrote:"Pavel Minayev" <evilone omen.ru> escribiσ en el mensaje news:a3gm8e$1m2f$1 digitaldaemon.com... | "Walter" <walter digitalmars.com> wrote in message | news:a3gh3a$1k44$2 digitaldaemon.com... | | > Your only option is to change the name on one of the interfaces. | | or Delphi? Like this: | | class foobar: foo, bar | { | void foo.baz() { ... } | void bar.baz() { ... } | } | Some agreed that it could be useful. I'm also for it, specially becausethisis illegal: interface I1 { int a(); } interface I2 { void a(); } class C:I1,I2 { void a() { return; } int a() { return 0; } } But if I could do: class C:I1,I2 { void I2.a() { return; } int I1.a() { return 0; } } Then there would be no problem. Or am I wrong? I think I am, but I don'twhy:DI don't see any reason why the latter version must be illegal. However, you should note, of course, that you would not be able to call either version of a() directly, without a cast. -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Mar 30 2003