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 performTaks() 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:
- Should I additionally make 3 separate interfaces, viz.
WalkService, TalkService & ThinkService, which extendsCapability.javaand autowire these classes in controller, or - Directly autowire
WalkServiceImpl, TalkServiceImpl & ThinkServiceImplin controller?
If there is altogether better approch for this, then please suggest that well.
Thank You
Aucun commentaire:
Enregistrer un commentaire