Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Classes and Interfaces

 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have come across a problem while going though K&B book on EJB 2.0...It actually requires some knowledge of java to figure out..
I am not quoting the actual problem, although it is something like this.....I have the following classes and interfaces....




The trick is to ensure that both A and B need to have the same method signatures, but i am not allowed to make A implements B
I though that may be I could try out with something like this as


as this would check whether the method declared by B is implemented by A, but then again, B extends C, and i need to provide implementation for C, whose methods i am not aware Of.

Can you please suggest some way in which i can ensure That the method definition in A matches the method declartion in B??

P.S: just to give a background, this concerns itself with component interfaces and bean classes
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why isn't A allowed to implement B?
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter,

From my example point of view if A implemnets B, then A has to implement C as well, whos methods A is neither aware of, nor required to implement.

From the actual problem point of view, A is a bean class and B is a component interface and C is an EJBObject. The spec requires that A should not implement B. If we do know the methods in EJBObject and we do provide the their implementation in A, then it would mean that the client would be able to directly communicate with the bean class, through the EJBObject methhods that the bean class defines, which again is a violation of Bean architecture.
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a solution???
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you possibly want something like this:
 
Mak Smash
Greenhorn
Posts: 17
C++ Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If you implement an interface B and that interface extends to another interface C that time you must have to implement method of both the interface otherwise compiler wont allow...

If you dont know what methods interface C has... you can find using javap -p InterfaceName... This will show you all the methods inside that interface...
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Sounds like you possibly want something like this:



Agreed!!!...Thanks a lot. Really was very simple
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mak Smash wrote:Hi,

If you implement an interface B and that interface extends to another interface C that time you must have to implement method of both the interface otherwise compiler wont allow...

If you dont know what methods interface C has... you can find using javap -p InterfaceName... This will show you all the methods inside that interface...


Yes I can, but that option is not viable due to some design issues.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic