What kind of naming convention is appropriate for ViewModel classes?
Example: for HomeController, Index view? HomeIndexViewModel doesn't seem right.
Naming Conventions for Name of a Type“ViewModel” is simply added to a “Page”-suffixed name to yield the name of its ViewModel. However, only “Model” is added to a “View”-suffixed name to yield the name of its companion ViewModel.
ViewModel is a class that is responsible for preparing and managing the data for an Activity or a Fragment . It also handles the communication of the Activity / Fragment with the rest of the application (e.g. calling the business logic classes).
I use the following pattern because it's clear and unambiguous :
EmployeesViewData.
That's what I use and what I've seen in sample applications as well.
About your added example: Imho the name of the class should specify what kind of data it contains. "....IndexViewData" is rather meaningless. What exactly is displayed on that page? Try to summarize it in 1 or 2 word(s) and add 'ViewData' behind it.
Or else just take the name of the controller and drop the "index". HomeViewData sounds fine to me.
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