Looking at your code you are already using polymorphism through the IRecovery
interface. Basically polymorphism is a way of interacting with different types of objects through a common interface. This can be through an actual interface definition, for example IRecovery
, or a base class such as BaseRecovery
. You can read more here:
Polymorphism (C# Programming Guide)
From looking at your code samples I would make one or two changes. First make your BaseRecovery
class abstract so that I instance cannot be created. This will force you to use either LoanRecovery
or FineRecovery
which are more meaningful, concrete, implementations of IRecovery
. In your programe.cs replace the new BaseRecovery
with either new LoanRecovery
or new FineRecovery
based on what you want to display in your view.
When it comes to updating the model with values from your presenter all you have to do is run your reflection code. The SetModelPropertiesFromView
method should take a IRecovery
and in there you call GetType()
which will return type information for whatever type of object IRecovery
is pointing at. From this type information you can then enumerate the properties and update each property with the values from your view.
EDIT 1:
It just occurred to me that you run into a problem with this. The reason being you are using the same view for updating two different models so how does the view know which model it is updating and therefore which properties need to be set. The only thing I can think of is your SetModelPropertiesFromView
looks at the type information and if it's one type then update some properties, but if it's another type then update other properties.