I am building a WPF application which uses a third party library to fetch objects which I want to allow the user to interact with.
The objects are returned as interface types. Am I right in thinking it is good practise to create wrapper classes for these objects instead of binding directly to the interface returned e.g (ICustomer)?
If so, what is the best way to do this? My current thinking is to inject the service into my view model. Then create my own version of the customer class (ClientCustomer
) on the client. When I call get customers on the service it will return a list of ICustomer
.
For each of these, I will create a new instance of ClientCustomer
passing in the ICustomer
object and client customer can simply return the underlying properties. This will leave me with a list of ClientCustomer
objects which I can bind to instead of binding directly to the List of ICustomer
:
public class ClientCustomer
{
public ClientCustomer(ICustomer c)
{
this.customer = c;
}
public string Name
{
get { return this.customer.Name;}
}
//Other properties in a similar way to Name
}
public class CustomerViewViewModel : ViewModelBase
{
ICustomerService svc;
public ViewModel(ICustomerService svc)
{
this.svc = svc;
Customers = new List<ClientCustomer>();
var custs = svc.GetCustomers();
custs.ForEach(c => Customers.Add( new ClientCustomer(c));
}
public List<ClientCustomer> Customers {get;}
}
Is this a good approach?
I'm also unsure how to handle complex types which ICustomer
contains. For instance ICustomer
has a List of Bank accounts IBankAccount
.
Do I need to wrap the Bank Account object in a similar way as well?