Results 1 to 10 of 10
Thread: interface
- 01-02-2011, 02:10 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
interface
hi, if a class implements two interfaces, Interface1 and Interface2, and both the interfaces have a method with same signature then no matter what reference (the class or any of the interfaces) i use to invoke the method, the same method will be executed. can some one give an ex. which can explain the benifits of implementing two interfaces with the same method signatures.
- 01-02-2011, 02:22 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-02-2011, 02:30 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
thanks for the reply Jos. but don't you think, that java allows such kinda implementation leaving the developer in confusion whereas C++ is strict about not allowing such kinda implementation.
- 01-02-2011, 02:30 PM #4
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 11
- 01-02-2011, 02:34 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
the complier allows it.. so we can conclude as YES
- 01-02-2011, 03:10 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Indeed; the language would need to be changed to 'fix' this, i.e. the method overloading mechanism needs to be changed, additional keywords or whatever need to be defined all for this. It is much easier and cheaper to allow a single method implementation to 'fit' two or more interfaces. Java is not C++.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 01-02-2011, 03:19 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
ya, java tried to solve the C++ diamond problem (for the compiler), and left the decision on the developers.... good busniess logic :)
- 01-02-2011, 03:28 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 01-02-2011, 03:53 PM #9
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
hye.. can you share some more similar things?
- 01-02-2011, 04:13 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar thing ... my pet peeve complaint is that one isn't allowed to refer to member variables of an object before the object is constructed (which is understandable) while it is allowed to use methods called by a superclass constructor that can be overridden by a subclass. I understand why it happens (simplicity of the vtab at construction time) but I just don't like it ;-)
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Need help with Interface
By karanhs6 in forum New To JavaReplies: 18Last Post: 12-14-2010, 10:47 AM -
help me about Interface
By manhtungtnk28@gmail.com in forum New To JavaReplies: 3Last Post: 11-23-2009, 06:15 PM
Bookmarks