Usable API
Here are a couple of suggestions when you design your API. They are mostly about dealing with passing collections:
- "params" is your friend, it is much nicer to be able to write this:
foo.WithArgs("Bar","Foo","Fubar");
foo.WithArgs( new string[] { "Bar", "Foo", "Fubar"} );
- One very important this to be aware of, try very hard not to write declarations like this one:
void WithArgs(string username, string password, params string[] optional);
- When you need a method that takes several collection parameters, try to ensure that the most commonly used argument at the end, so it would be easier to extend:
FindAll(Order[] orders, params ICriterion[] criterias)
- Finally, when you have code like the above, be sure to specify an overload that takes a single parameter of the first one, like this:
public static T FindFirst(Order order, params ICriterion[] criterias)
Comments
Comment preview