I had a lot of ViewModels that reused a lot of the same code over and over again, mostly for listing, adding and editing data in a remote database. So I created the following base view models that extend from the main base view model:
public class ListBaseViewModel<Context> where Context : class, IIdEntity { }
public class AddBaseViewModel<Context> where Context : class, IIdEntity { }
public class EditBaseViewModel<Context> where Context : class, IIdEntity { }
They just hold the commands for the elements which all of the pages that extend them share. So for example if you could have:
public class ProductListViewModel : ListBaseViewModel<Product>{ }
public class ProductAddViewModel : AddBaseViewModel<Product>{ }
public class ProductEditViewModel : EditBaseViewModel<Product>{ }
Is there a reason that this would be a bad idea? At the end of the day I could override any of the methods within the BaseViewModels if I wanted to change how a product is sent to the REST API I could just override the Add() method.
To me it seems a no brainer as in a scenario where I might have around 30 pages per function (list, add, edit) then I would have 90 viewmodels overall repeating the same code again and again and when each view model could be around 50 lines that ends up at 4500 lines almost.
P.S IIdEntity is a type with an Id and some other parameters that these ViewModels would use