In action, is it better to write a get/post request as a class or divide it into two classes?

Source: Internet
Author: User
    • First Kind

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

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

What kind of design is more reasonable?

Reply content:

    • First Kind

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

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

What kind of design is more reasonable?

The individual thinks to divide the specific use way. In the case of Singleton mode, two classes have no advantage, and a class is actually more encapsulated. A request for an instance, seemingly divided into two classes can reduce overhead, but I still think a class on the line.

Principle, get/put/post/delete to English a URL above the data set of four kinds of operations, code should be operating the same concept, so put in a class inside when 4 methods are very good. However, many times, we use post is not the original meaning of post, so look at your specific business logic is what it looks like.

This person likes to see, there is no absolute standard.
Another thing to consider is the routing overhead, but it's no different now.

  • Related Article

    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.