Java interface expands questions

I need to implement an RMI server that will become the interface for two other RMI services. Therefore, I decided that the logical task is for the interface to implement the interfaces for the other two services.

public interface FrontEndServer extends Remote, BookServer, StudentServer
{
    // Block empty so far
}

However, there is a method on StudentServer

/**
 * Allows a student to borrow a book
 * 
 * @param studentID of the student who wishes to borrow a book
 * @param bookID of the book the student wishes to borrow
 * @throws RemoteException
 * @throws StudentNotFoundException when a student is not found in the system
 */
void addBookToStudent(int studentID, int bookID) throws RemoteException, StudentNotFoundException;

I would also like to FrontEndServerchoose BookNotFoundException, as this service will also check if the book really exists before trying to add details.

Is this possible, or is my design idea completely turned off, and is it really a bad design idea, as if the other interfaces were changing and that’s it? And would I rather write method signatures for all methods inside FrontEndServer?

+3
6

( , ), , . , .

:

interface A {
  void foo();
}

interface B extends A {
  void foo() throws IOException;
}

A a = new B() { ... }
a.foo();

IOException, . .

, , :

interface A {
  void foo() throws IOException;
}

interface B extends A {
  void foo();
}

A a = new B() { ... }
try {
    a.foo();
} catch (IOException e) {
    // must catch even though B.foo() won't throw one
}

BookNotFoundException RuntimeException RemoteException. , .

+15

, ? -, ?

, "" - . . , ? CafeteriaService DormitoryService .

, addBookToStudent BookNotFoundException. , , - . . , BookNotFoundException, , ; , "" ? ( , .) : CheckOutLimitExceededException, UnpaidFinePendingException, AdultLiteraturePermissionException ..

, , .

+5

:

  • addBookToStudent , BookNotFoundException. , StudentServer , , .

  • - ObjectNotFoundException BookNotFoundException StudentNotFoundException, addBookToStudent ObjectNotFoundException.

  • , StudentServer BookServer, , FrontEndServer. , StudentServer , FrontEndServer.

+2

API API, . , RMI .

, :

  • API,
  • , API
+2

, BookNotFoundException RemoteExcepiton.

, StudentServer. , - BookNotFoundException. , , , , .

+1

, . , BookServer , , .

addBookToStudent FrontEndServer, . , .

If you think about it, you will see that it is logical. Yours FrontEndServercan be used as BookServer with some code. Code during compilation expects exceptions defined in BookServer. Then, at runtime, a sudden exception is raised by the BookServer browser, which is not defined in the BookServer interface. If this piece of code knows that BookException is unexpected, it has no catches or directions to handle it.

+1
source

Source: https://habr.com/ru/post/1704297/


All Articles