0

I'm looking for design ideas for something like a composite ViewModel. I'm facing a situation where a lot of ViewModels need CRUD operations and some need refresh operations. A minority of ViewModels needs both of them and I want to compose functionality. I would like to avoid inheritance for functionality sharing. When I separate CRUD from Refresh I end with a inheritance chain like this: MyViewModel : RefreshBaseViewModel : CrudBaseViewModel : BindableBase.

Any design ideas are very welcome I'm a bit stuck :) What do you think about injecting commands?

  • When you say ViewModel exactly what responsibility do you, in your designs, mean? I mean you, not something you quote or link me to. What is your vision of your ViewModel's responsibility? – candied_orange Jul 15 '18 at 20:17
  • @candied_orange For me its the glue between View and Model/Business Logic. It is responsible for input validation and calling service methods to retrieve / store models from / into repositories – Grrbrr404 Jul 16 '18 at 6:03
  • The Decorator pattern might work nicely for layering in the different pieces of functionality, though it's hard to say without more information about the types of operations you need to support. – Bradley Uffner Jul 17 '18 at 14:59
  • Oh yes decorator pattern is a nice idea, but actually hard to use in my environment, using dependency injection. When you think of commands this is what I need: Load model from repository/backend, refresh model from backend, create, delete. Sometimes my ViewModel just needs the loading capabilites, sometimes loading and editing is needed, sometimes loading, editing and refreshing – Grrbrr404 Jul 18 '18 at 5:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.