A
A
Amir Kenesbay2021-01-31 17:59:55
Java
Amir Kenesbay, 2021-01-31 17:59:55

Need to develop a hierarchy of library workers?

Good afternoon!
please tell me (explain) what else needs to be done with this task with abstractions and interfaces.

I understand what needs to be done 4 interface Reader, interface Librarian, interface Supplier, interface Administrator. With my own classes, but then how it cuts off, I try to do it in IDEA.

Description
It is necessary to develop a hierarchy of library workers. It is necessary to implement the combination of several roles in the library in one executor through interfaces. Each object in the program has a specific set of actions.
Often the programmer who creates an object does not represent all the situations in which it will be used. Also, the programmer using the object often does not know all its details.
Interfaces are used to convey information about what an object should be able to do.
An example of interfaces in our library is the concept of a role on a project. Each role implies a set of specific operations that the user object must "be able to" - User in the program.
Functionality of the program
Create a hierarchy "Library Users" with the following interfaces:
Reader - takes and returns books.
Librarian orders books.
Book Supplier - Brings books to the library.
Administrator - finds and issues books and notifies of delays in the return time.
In the public static void main method, create 2-3 objects that implement these interfaces.
Additional Information
Please note that the user (User) can have several interfaces. Objects of class User can interact with each other (for example, a librarian orders from a supplier).
Implementation Example
For example, an administrator should have an overdueNotification(Reader reader) method. Methods can take other users as a parameter. For example, a reader borrows books from an administrator, a librarian orders from a supplier, and so on.
Create some classes that demonstrate the use of interfaces. In particular, demonstrate overlap, such as a provider who can also be a reader, a librarian who is an administrator, etc. The implementation of the methods described in interfaces is optional, but it is desirable to demonstrate how methods should be called on objects.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-01-31
Hasanly @azerphoenix

Good afternoon!
Create multiple interfaces.
For example, iReader, iLibrarian, iSupplier and iAdministrator. (The names are given for illustration purposes only. It is advisable to follow the Java naming convention)
Next, describe the methods for each interface.
For example, for iReader -

// сигнатуры методов могут отличаться
takeBook(); // взять книгу
returnBook(); // вернуть книгу

For iLibrarian For iSupplier For iAdministrator
orderBook(); // заказать книгу
bringBook(); // принести книгу
findBook(); // найти книгу
overdueNotification(User reader); // уведомить о времени возврата

Next, you need implementations of these interfaces.
Reader implements iReader
Librarian implements iLibrarian
Supplier implements iSupplier
Admin implements iAdministrator

In general, we implement interfaces and implement these interfaces.
If, for example, Admin can not only notify users about the expiration of the return period, but also read books, then we will Admin implements iAdministrator, iReaderimplement the required interface too.
And of course, we need the Book class, which will represent the book.
This is a simple task in OOP. Maybe. that the names of classes and interfaces can be made even more beautiful, but I whipped up to show you the idea.
You can also, for example, inherit All these users from the User object.
Those.
Reader extends User implements iReader
And in interfaces, for example, use generic type. Thus, only classes extending the User class can implement this interface.
For example,
interface iReader<T extends User>
Then the above line will look like this:
Reader extends User implements iReader<Reader>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question