File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem with Classes and Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with Classes and Interfaces" Watch "Problem with Classes and Interfaces" New topic
Author

Problem with Classes and Interfaces

jishnu dasgupta
Ranch Hand

Joined: Mar 11, 2011
Posts: 103

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


If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Why isn't A allowed to implement B?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
jishnu dasgupta
Ranch Hand

Joined: Mar 11, 2011
Posts: 103

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

Joined: Mar 11, 2011
Posts: 103

Is there a solution???
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Sounds like you possibly want something like this:
Mak Smash
Greenhorn

Joined: May 15, 2011
Posts: 17

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

Joined: Mar 11, 2011
Posts: 103

Matthew Brown wrote:Sounds like you possibly want something like this:



Agreed!!!...Thanks a lot. Really was very simple
jishnu dasgupta
Ranch Hand

Joined: Mar 11, 2011
Posts: 103

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Classes and Interfaces
 
Similar Threads
Design issue with Server
Doubt regarding multiple and hybrid inheritance in java.
Need help!!
Reusabilty of code lack in using interfaces for polymorphism