Explicit API methods and generic parameter-based API methods

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.

- ?

+3
3

(), - "" .

, . , age , ..

, int C, .

, () , API-, . (b) - , , .

+2

, . , - , ( , , , ..). API, , , struct , struct struct , struct API .

+1

, , . , (.. / ), b, .

(a), . , , :)

0
source

Source: https://habr.com/ru/post/1702349/


All Articles