提示在C#3写流利接口 [英] Tips for writing fluent interfaces in C# 3

查看:142
本文介绍了提示在C#3写流利接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些好的建议在C#流利的接口我。我只是了解自己,但热衷于听别人怎么想我读的文章之外。特别是我后:

I'm after some good tips for fluent interfaces in C#. I'm just learning about it myself but keen to hear what others think outside of the articles I am reading. In particular I'm after:


  1. 精通的时候太多了?

  2. 是否有任何流利的模式?

  3. 什么是C#,使流畅的接口更流畅(如扩展方法)

  4. 是一个复杂流畅的界面仍然能说一口流利的?

  5. 重构以一口流利的接口到达或重构现有流畅的界面

  6. 任何好的例子在那里,你工作过的或可以推荐?

如果你能发布后每一个提示或思想,或什么的。我想看看他们是如何被表决了。

If you could post one tip or thought, or whatever per post. I want to see how they get voted on, too.

感谢您提前。

推荐答案

在您的第4点;

是的,我认为一个复杂流畅的界面仍然可以流畅。

Yes I think that a complex fluent interface can still be fluent.

我觉得流利的接口是有些妥协。 (虽然一个好的!)已经有很多研究使用自然语言进行编程和一般的自然语言不是precise足以EX preSS方案。

I think fluent interfaces are somewhat of a compromise. (although a good one!) There has been much research into using natural language for programming and generally natural language isn't precise enough to express programs.

流利的接口构造,使他们写这样一门编程语言,只有你可以在一个自然语言的前preSS是允许的什么一小部分,但他们读起来就像自然语言。

Fluent interfaces are constructed so that they write like a programming language, only a small subset of what you can express in a natural language is allowed, but they read like a natural language.

如果你看一下犀牛嘲笑例如相比于正常的库编写部分已被复杂化了。我把我更长的时间来学习主要是由于流畅的界面,但它使code很多更容易阅读。由于程序通常写一次,读了很多超过一次,这是一个很好的权衡了。

If you look at rhino mocks for example the writing part has been complicated compared to a normal library. I took me longer to learn mostly due to the fluent interface but it makes code a lot easier to read. Because programs are usually written once and read a lot more than once this is a good tradeoff.

所以晋级我点了一下。说一口流利的界面,复杂的写,但易于阅读仍然可以流畅。

So to qualify my point a bit. A fluent interface that's complex to write but easy to read can still be fluent.

这篇关于提示在C#3写流利接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆