7

Just as there is a naming convention for the Observer pattern (or rather, a naming convention for events in languages such as C#) using Event/Handler passing EventArgs and such, are there naming conventions that you use to easily highlight other patterns in your code?

edit: I originally wanted to ask about the Strategy pattern, but figured it would be helpful to know about any other conventions that might exist for common patterns as well.

4

1 回答 1

6

我通常让类的后缀指定它是否使用模式的一些想法——即。我所有的 ViewModel 都以 ViewModel 结尾...我的 View 以 View 结尾,依此类推。对于您一直使用的模式(Factory、ViewModel、Strategy)来说,这真是太好了。有些是更内在的(我还没有命名一个类 MonoState)——我猜它与类的主要响应能力有关——或者我没有在实现细节之后命名它(Monostate 是我的实现细节书)。如果它所做的符合它模拟/包含的模式 - 它会获得一个带有模式名称的后缀。

如果不出意外,它可以帮助我的课程的读者找出实现中的一些推理,而我不写任何评论。如果可以的话,我会尝试使用通用名称(没有特定于 C# 的名称)——尽管 ViewModel 有点专门用于 WPF 世界。

我的代码库中有很多 IPricingStrategy、ICustomerViewModel 等。

希望这对我来说和写它时一样有意义:-)。

于 2010-07-31T21:17:24.767 回答