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 EventArg开发者_JAVA技巧s 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.
I usually let the postfix of the class designate if it uses some of the ideas of a pattern - ie. all my ViewModels end in ViewModel... My Views end in View and so on. It is really nice for the patterns you use all the time (Factory, ViewModel, Strategy spring to mind). Some are more intrinsic (I have yet to name a class MonoState) - I guess it has to do with the main responsebility of the class - or that I don't name it after an implementation-detail (Monostate is an implementation detail in my book). If what it does fits with the pattern it emulates/encompasses - It gets a postfix with the name of the pattern.
If nothing else, it helps readers of my classes to figure out some of the reasoning in the implementation with me writing no comments. I try to use the general name (no C#-specific names) if I can - although, ViewModels are somewhat specialized to the WPF world.
I have lots of IPricingStrategy, ICustomerViewModel and so on across my code-base.
Hope that makes as much sense as it did to me while writing it :-).
精彩评论