1. Single Responsibility
The English name of the single duty principle is the Responsibility Principle, the srp, and the single responsibility principle is defined as: there should be and only one cause for class Changes.
Example 1: the user management is split into two interfaces, Iuserbo is responsible for the User's attributes, in short, Iuserbo's responsibility is to collect and feedback the User's attribute information, iuserbiz responsible for the User's behavior, to complete the maintenance and change of user information
<?PHP/** *business Object (business object), responsible for user collection and feedback of User's attribute information*/ Interfaceiuserbo{functionSetuserid (/*String*/ $userId); functiongetUserId (); functionSetPassword (/*String*/ $password); functionSetusername (/*String*/ $userName); functionGetUserName (); } /** *business Logic (business logic), responsible for user behavior, to complete the maintenance and change of user information*/ Interfaceiuserbiz{functionChangePassword (/*String*/ $userId,/*String*/ $password); functionDeleteUser (/*Iuserbo*/ $userBo); functionMapuser (/*Iuserbo*/ $userBo); functionAddorg (/*Iuserbo*/ $userBo,/*String*/$orgId); functionAddrole (/*Iuserbo*/ $userBo,/*String*/$roleId); } /** *business Logic (business logic), responsible for handling user behavior*/ InterfaceIuserinfoextendsiuserbo,iuserbiz{}classUserInfoImplementsiuserinfo () {}
Example 2:
/** *business Object (business object), responsible for user collection and feedback of User's attribute information*/ Interfaceiuserbo{functionSetuserid (/*String*/ $userId); functiongetUserId (); functionSetPassword (/*String*/ $password); functionSetusername (/*String*/ $userName); functionGetUserName (); } /** *business Logic (business logic), responsible for user behavior, to complete the maintenance and change of user information*/ InterfaceIuserbizextendsiuserbo{functionChangePassword (/*String*/ $userId,/*String*/ $password); functionDeleteUser (/*Iuserbo*/ $userBo); functionMapuser (/*Iuserbo*/ $userBo); functionAddorg (/*Iuserbo*/ $userBo,/*String*/$orgId); functionAddrole (/*Iuserbo*/ $userBo,/*String*/$roleId); } classUserboImplementsIuserbo {}classIuserbizImplementsiuserbiz{}
Design Pattern: 6 Major design principles (php Version)