In action, should GET/POST requests be written as a class, or should they be divided into two classes separately?

Source: Internet
Author: User
The first {code...} and the second {code...} are more rational designs?
  • First

namespace app\action\user;class  Login{        function get(){       }       function  post(){     }}
  • Second

namespace app\action\user;class  Login{        function service(){       } }
namespace app\action\user;class  PostLogin{      function  service(){     }}

Which design is more rational?

Reply content:
  • First

namespace app\action\user;class  Login{        function get(){       }       function  post(){     }}
  • Second

namespace app\action\user;class  Login{        function service(){       } }
namespace app\action\user;class  PostLogin{      function  service(){     }}

Which design is more rational?

I personally think it should be divided into specific usage methods. In the singleton mode, two classes have no advantages. One Class is actually better encapsulated. One request to an instance seems to be divided into two classes to reduce the overhead, but I still think one class is enough.

In principle, GET/PUT/POST/DELETE are the four operations on the data set above a url in English. The Code should be the same concept, therefore, it is good to put four methods in a class. However, in many cases, the use of POST is not the original meaning of POST, so it depends on your specific business logic.

This is a matter of personal preferences, and there is no absolute standard.
There is also a need to consider the routing overhead, but now there is no difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.