Home >Java >JavaBase >What principles should be followed when designing interfaces in java

What principles should be followed when designing interfaces in java

王林
王林Original
2019-11-23 10:15:363275browse

What principles should be followed when designing interfaces in java

Normative suggestions for designing java interfaces:

1. Responsibility principle

When designing an interface, the interface must be clear Responsibilities, that is, interface type, what business problems the interface should solve, etc.

2. Principle of Unity

Under the condition of clear interface responsibilities, try to make the interface as single as possible , that is, an interface only does one thing, not two or more. Many non-senior interface designers, when designing interfaces, always think that the more things an interface does, the more awesome it will be. This is a very serious misconception.

3. Protocol specification

When designing the interface, the interface protocol should be clearly defined. Whether to use HTTP protocol, HTTPS protocol or FTP protocol should be determined according to the specific situation.

(1) FTP protocol (File Transfer Protocol, referred to as FTP) is a set of standard file transfer protocols used to transfer files, such as .txt, .csv, etc. For general file transfer, the FTP protocol is used

(2)HTTP protocol, suitable for business scenarios with low or no security requirements

(3)HTTPS=HTTP SSL, suitable for business scenarios with high security requirements

4. Path rules

Since api obtains a resource, try to use nouns in the URL instead of verbs

/api/ v1.0/Pruduct/2019

/api/v1.0/Users/2019

5.http request method

Interface basic access protocol : get (get), post (new), put (modify) and delete (delete)

get /users: List all users

get /users/id: Get based on id User

post /user: New user

put /user/id: Update user based on user id

delete /user/id: Delete based on user id

Recommended tutorial: Getting started with java development

The above is the detailed content of What principles should be followed when designing interfaces in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn