3
I own three classes:
- Repositoriosolicitant
- Repositoriomotorist
- Repositorioviagem
All have the following methods with the exception of Repositorioviagem which does not have "Change". The Object can refer to the classes Driver, Requester and Travel.
- Add void
- Remove void
- Change Boolean
- Seek Object
- Exhibited void
- Arraylist searches
I would like to know how to implement a single Interface for the 3 Repositories with the above methods in a generic way, so I can use any class I pass. Whether Add with Requester, Driver or Travel.
Wow, created the class with the same name I was creating :p Just a detail, don’t need
public
and it is worth adding that the classRepositorioViagem
will have to implement everything, regardless whether to use the method or notalterar
.– user28595
@diegofm I was doubtful in changing too, will be that the best way is to create
2 interfaces
?– Sorack
No, just don’t implement, leave the method empty, or launch a
UnsupportedOperationException
within the method should any unsuspecting attempt to implement– user28595
She’d be empty anyway.
– La Treta
my doubt was more about the shape that would be "typed", I believe that the lack of <T> in the interface name bugged every time I used T in the methods.
– La Treta
@Diego it is interesting to put the part of
public
and Exception in response?– Sorack
@Sorack look, the exception part I find valid as suggestion, now the modifier, I never used, but I was in doubt if it is dispensable even.
– user28595
@diegofm the modifier can be
protected
so you can specify– Sorack
@sorack, you may not, all interface methods are obligatorily public, so the IDE does not complain about the public, but neither does it complain if it does not add it. protected from syntax error.
– user28595
@diegofm true... so I didn’t even need to specify it anyway
– Sorack