English 中文(简体)
在以下情况下,我可以避免超越一种方法吗?
原标题:Can I avoid overriding a method in the following scenario?
  • 时间:2012-05-24 19:56:57
  •  标签:
  • c#
  • interface

假设有5家汽车租赁公司, 当有人在网上租房时,

现在,如果有标准的方法可以发送XML来租车,那么这很容易,但让我们假设每个机构与不同的界面合作发送租车,每个界面以不同格式发送XML,因此当需要解析时,你无法使用一种标准方法,你需要能够覆盖处理多个界面的方法。举例来说,你可能有以下2种:

<Rental>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Pickup time="13:00"/>
<Date>06/06/12</Date>
</Rental>

VS 甚高

<Rental>
<Name>
<First>John</First>
<Last>Doe</Last>
</Name>
<Pickup time="13:00" date="06/06/12"/>
</Rental>

如果每个汽车代理公司对处理租赁使用不同的接口,是否是覆盖一种方法5次的唯一办法,而且与每个新代理公司相比,它必须再次增长,还是对此采取更简单的办法?

问题回答

使用 < a href=> "http://en.wikipedia.org/wiki/Decorator_pattern" rel=“nofollow” >Decorator 样板 。假设您正在做,您可以有一个提供租车数据的基本对象,然后用另一个正确格式化数据的对象(或装饰它)包起来(或装饰它)。您需要为每个不同的租车代理机构制作一个seperate 装饰器。

如果新机构唯一需要做的就是处理将数据分割成内部数据列报,然后用一切手段都非常成功的话。 为什么要花心思去研究那些似乎非常适合分开业务的明智之处呢?

我想,如果你真的想要的话,你可以以多种方式解决这个问题。我会玩弄一种想法, 来创建一个 Ai 或 an 来匹配最合适的输入。 但是任何解决方案都可能比执行“ 种族隔离- 客户数据” 的独特功能更昂贵。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签