In our team during Code Review I see something strange. One of our developer create class to read data from file. In this class he create method to return this data to ViewModel. He use BindableCollection (from Caliburn.Micro) as return type.
public BindableCollection<T> GetData()
{
//read data
}
But I think that is a bad practice beacuse BindableCollection is a collection to work with ViewModel not with model. I write code looking like this:
public List<T> GetData()
{
//read data
}
Of course in ViewModel he write Items=new model.GetData() and he think that is better than mine Items.AddRange(new model.GetData()). Result is the same.
I think his code break SOLID rule. Is any other good reason to change this code?
Maybe ObservableCollection is what you are looking for ? You can bind it to a view with CollectionChanged Events and so on.
ObservableCollection
And i dont know the Caliburn.Micro BindableCollection but mainly you should use an IObserable inheriting collection in ViewModel and an IList or ICollection in model.
When your ViewModel is loading data, you cann easily create an ObservableCollection with an IList or ICollection by constructor.
I Hope this helps.
var myObservableList = new ObservableCollection<MyModelType>(myModel.NiceList);
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