When determining the API available to the client, which of the industry best practices is as follows:
a) Defining an API set of Explicit APIs, each of which has a very narrow and specific purpose, for example:
SetUserName <name>
SetUserAge <age>
SetUserAddress <address>
b) Defining a set of more generalized API methods based on parameters, for example:
SetUserAttribute <attribute>
enum attribute {
name,
age,
address
}
My opinion:
In favor of (a)
For boolean-based methods (e.g. EnableFoo), I would definitely approve option (a), as the intent is much more clear, and extensions in the future will be less needed, and this makes the code more readable.
, EnableDisableFoo, , , , .
, , .
(b)
(b) - API, . (a) API , , . (b) enumeration/parameter. () - , , - , .
, . , , API.
- ?