Add Helpers and usecases in ViewModel is valid or not?

An Architecture Question Please.
From your view do you think it is a good idea to inject a helper class in the view model which is not a usecase.
Forexample, I have a viewmodel for a view that displays horizontalList of People, and every period of time I update this list of ppl and display a toast for the removed one and also for every new one I display a toast. I would like to do the comparisons in a helper class and inject it in the ViewModel, and the reason for that is I really have a very big business in this view, so I wanted to split the responsibilities, so in the same view I have also different horizontal list for items which I am calculating the prices and changing them as well and for this I created ItemHelper. Therefore, is it valid to inject two or more Helper objects beside the injected usecases in the viewmodel?.

Please let me know if the question is not that clear. Thanks in advance :slight_smile:

Let me try answering this in stages…

  • Can you use other classes in your viewmodel? Yes!

  • Can those classes be named “…Helper”? Yes, though that naming system worries me. I find that newcomers lump unrelated code together in “helper” classes for convenience, without thinking through whether that makes sense. I would rather that there be a name that more tightly scopes the work that the class is supposed to do.

  • Should those classes be injected? Maybe! :grin: If you need to provide an alternative implementation, for testing or for different strategies or something, then injection clearly makes sense.

1 Like