New answers tagged naming
"OnXXX" is typically something with events, but different platforms have different naming conventions, so the exact role depends on the language, which can get confusing. In .net UI classes, a method name with the prefix "On" is a method which causes an event to be fired. For example, Button.OnClick() is the method which fires the Click-event. The OnXXX ...
It's just one of the many meanings of the English word word "on", used as a preposition. It indicates when the action occurs. So onButtonPressed() is called when the button is pressed. The function could be re-named whenButtonPressed(), but that's longer and not idiomatic
Prefix "on" is most often used to indicate that method is intended to be used as a callback, i.e. not called directly, but set as a handler for some event. For example, when you write method named onClick, you probably won't call it directly, but rather expect that GUI toolkit will call it once user clicks a button.
Just use the simple constructor. In this particular case factory is a more obscure API for no reason. Add the factory when it's clearly needed.
I do not think there is a standard for this. The majority of english nouns does not come with this problem. So if you do not want to add a term like "list" or "collection" to the variable name, a possible solution is to circumvent that problem by simply choosing a different term. In your example, one could use "sequence" instead of "series" (if that is the ...
> Object creation: when should I expose a factory vs wrapping class? Answer from unit-testing point of view: If you want to do unit-testing and the test requires you to change the object-creation of child-items the factory (method or class) is the way to go. If your program is scattered with several IOrderItem orderItem = new OrderItem(...) you ...
I do not quite understand your question. And I think there are some misconceptions: I) A factory is a design pattern used to separate object creation from object consumption. There are two possible ways to deal with that: 1) You delegate instance creation to a separate object 2) A static method is used to create instances The advantage: Dependencies are ...
Top 50 recent answers are included