You can create a general FlightViewModel that encapsulates OutFlight and InFlight objects. Thus, FlightViewModel has all the common properties and is built on the basis of OutFlight and InFlight objects (for example, passing them in the constructor). It may have an additional property indicating whether it is a deflection or a stream (as an enumeration or something else).
This makes FlightViewModel basically an abstraction of your specific OutFlight and InFlight types. FlightViewModel will also contain only those properties that you really need in your view and in the correct format so that it can be easily used in the view.
Then the view model of your view will have a set of FlightViewModel objects.
public class FlightViewModel { private Flight _flight; public FlightViewModel(OutFlight outFlight) { FlightNumber = outFlight.FlightNumber; FlightType = FlightType.OutFlight; _flight = outFlight; } public FlightViewModel(InFlight inFlight) { FlightNumber = inFlight.FlightNumber; FlightType = FlightType.InFlight; _flight = inFlight; } public int FlightNumber { get { return _flight.FlightNumber; } set { _flight.FlightNumber = value; } } public FlightType FlightType { get; set; } ... other properties }
This is just an example, of course, but you get the point.
source share