Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with interface

 
Reshma Das
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with interfaces.
interface A {
}
interface B extends A {
public methods of Data
}
interface C extends A,Remote {
public methods of Data throws RemoteException
}
class Data implements B {
...
}
class server implements C {
}
class client {
A a;
clein() {
if (local)
a = new Data();
else
a = (A)Naming.lookup(.....);
Iam getting compilation errors saying methods defined in B or C can be accessed using A.
Iam i wrong in understanding interface concepts ?
 
amit ahuja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reshma Das:
Iam getting compilation errors saying methods defined in B or C can be accessed using A.
Iam i wrong in understanding interface concepts ?


I presume u the compilation error says "methods defined in B or C canNOT be accesses using A"
if that's the case, then compiler is right, u cannot do so, though u can access methods of A from B or C.
Simple inheritence...
 
Reshma Das
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know there is a problem in this . Can someone explain me how to handle this situation of writing 2 different interfaces for remote & local client. Iam confused on this part.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reshma, there should be only one interface. The one that has all the public methods of the Data class, then there are 2 class one for local and one for remote that implement this interface.
Mark
 
Reshma Das
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
Right now I did the same. One interface which says
interface A extends Remote {
method1 throws RemoteException();
.....
}
and my server and data class implements this interface.
I think for local client we should not use Remote, RemoteException. Iam struck with this point. Can u pls suggest me something ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic