1

In my application I have a form bean that is loaded with a list of services that implement a certain interface.

These services are there to detect which type of processing will be done (they represent checkboxes).

Later, after the form is submitted, these services are instantiated into a list which is then sent to a facade that processes each one through the method that is implemented by the interface.

Basic idea:

Bean[List] -> Controller -> JSP[Checklist] -> Controller[processes checklist and create Services accordingly] -> Facade [loops trough all services sent by the controller and executes them trough interface].

The main question is about if this is acceptable behavior/design.

[It looks wierd, but it allows easy growth and polymorphism, thats why I adopted it.]

Tiago Duque
  • 1,956
  • 1
  • 12
  • 31
  • Don't see anything wrong with it; services are meant to be used. As long as the services are autowired and the controller does not "_create_" them... What about the setup makes you uncomfortable? – Boris the Spider Nov 11 '16 at 10:43
  • I'm actually having a problem exactly with this "created" stuff. In fact I'm pre-populating the services list into the controller so I have only one place to modify when I create a new service. Now I'm trying to solve the "null pointer exception" raised by it being created by new. My current solution is autowiring it to the controller and then populating the list. Lets see if it will survive trough the request though. – Tiago Duque Nov 11 '16 at 10:46
  • Why not autowire them directly into a list by annotation or [`interface`](https://stackoverflow.com/questions/7446301/autowire-reference-beans-into-list-by-type)? – Boris the Spider Nov 11 '16 at 11:06
  • Could you somehow give me an example? Maybe a pastebin file with simple generic stuff. Now I'm trying to get runtime weaving work into the server but it seems overkill compared to your suggestion. – Tiago Duque Nov 11 '16 at 11:08
  • Nothing to hand, sorry. How about something like [this SO question](http://stackoverflow.com/a/14236573/2071828)? Define a custom annotation and then autowire all defined beans with that annotation? – Boris the Spider Nov 11 '16 at 11:13
  • It seems I got to an answer. I delegated the list creation to another class where I could easily autowire stuff and then made a method that returns this list. Now I autowire the service to the controller and it seems to work. – Tiago Duque Nov 11 '16 at 11:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127890/discussion-between-tiago-sirious-and-boris-the-spider). – Tiago Duque Nov 11 '16 at 11:48

0 Answers0