I'm developing a WPF Prism application, and everything is working fine. My view models all have interfaces, which are injected by MEF.
However, I don't really understand the benefit of interfaces for view models. After all, a view is tied to its view model, so I think there will never be other implementations.
Actually, I also have interfaces for my views. It seems that this is also overkill?
So my question is: can't I just remove all view and view model interfaces and inject the views and view models directly? Is there any reason to keep interfaces for views and view models?
Thx, L
ViewModel is one of the most critical class of the Android Jetpack Architecture Component that support data for UI components. Its purpose is to hold and manage the UI-related data. Moreover, its main function is to maintain the integrity and allows data to service during configuration changes like screen rotations.
VIEW: ( Platform Specific Code – USER INTERFACE ) What the user sees, The Formatted data. VIEWMODEL: ( Reusable Code – LOGIC ) Link between Model and View OR It Retrieves data from Model and exposes it to the View. This is the model specifically designed for the View.
In Spring MVC, the model works a container that contains the data of the application. Here, a data can be in any form such as objects, strings, information from the database, etc. It is required to place the Model interface in the controller part of the application.
View Model: It encapsulates the presentation logic required to support a use case or user task in the application. The view model is testable independently of the view and the model. The view model typically does not directly reference the view. It implements properties and commands to which the view can data bind.
It is an overkill. I understand that you may want to mock your ViewModels, but I think it's more important to be practical. Plus, why would you even need to mock your ViewModels? Any logic that needs to be mocked should be put into a service class IMHO.
Interfacing your VieWModels gives you the benefit of mocking them in a test, interfacing your Views looks like some overkill indeed. You won't interchange your views and UI testing can be done on mocks of your ViewModel so you won't really need to interface them I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With