I'm building a Spring application in which every entity(Person) which can perform 3 tasks, say, Walk, Talk & Think.
Since all of them are some sort of Person's capabilities, I'm thinking of making an interface Capability.java
which will have a method performTask()
.
Above 3 classes will implement Capability.java
& will also have their own set of other specific methods.
Since, these 3 classes are verbs, I'm making them as @Service
, i.e.
- WalkServiceImpl.java
- TalkServiceImpl.java
- ThinkServiceImpl.java
Also, I'm thinking of making one @Controller - PersonController
, which will call performTasks()
of these 3 classes.
To use these classes in PersoneController
, I'll have to autowire them. And as a general practice we should always @Autowire
the interface.
But here the 3 classes have a common interface, with which I'll not be able to call performTaks()
of all 3 services in the controller.
So, my question is, what should I do (A or B)?:
A. additionally make 3 separate interfaces, viz. WalkService, TalkService & ThinkService
, which extends Capability.java
and autowire these classes in controller?
B. Directly autowire WalkServiceImpl, TalkServiceImpl & ThinkServiceImpl
in controller?