Type Casting and the Factory pattern

前端 未结 4 1458
执笔经年
执笔经年 2020-12-14 13:15

I\'m having a hard time figuring out how to implement a factory pattern in a DTO mapper I\'m trying to create. I\'m pretty sure I need to rethink my design. Here is a very s

4条回答
  •  孤城傲影
    2020-12-14 13:50

    There is no easy way around this.

    In order to use the PilotNumber property you need the Pilot type. Using a Factory pattern means you are giving up the different sub-types of Person.

    If it's any consolation, the BCL has similar patterns,

     var req = WebRequest.CreateRequest("http://someUrl");
     ((HttpWebRequest)req).Contentlenght = ...;
    

提交回复
热议问题