If I have a class Userand its account can be suspended by adding an entry to the table suspensions, which of these class / method signatures, in your opinion, is more appropriate?
User
suspensions
User::suspend($reason, $expiryDate); Suspension::add($userid, $reason, $expiryDate);
This is a simple example, but I have this situation throughout my application. On the one hand, I would like to make it a method of the User object, since the action being performed is directly related to this user object, but, on the other hand, its method on the suspension object seems a little cleaner.
What do you think?
you pause the user.
User.Suspend()
User.Suspend "" . , , , .
User.Suspend
. OO . , () ( ). , , , . , User.
: ? , , .
, / . , , User. , Suspension . , User.
, , , User.
, Suspensions, , :
class SuspensionManager suspendUser(....) getSuspendedUser(...) ....
* 100% , , /
. , OOAD. , User Suspension . User , ( ), Suspension , ( ). UserSuspention, .
OOAD SOLID. , Suspension , SRP ( )..., .
API :
public class UserSuspension { public void SuspendUser(User user, Suspension suspension) { ... } public void SuspendUser(Guid userId, string reason, DateTime expiryDate) { ... } }
Suspension::add(), . , , , (.. , ), : User::suspend(), , a "suspended" User, - - .
Suspension::add()
User::suspend()
"suspended"
, , User::suspend() , , , User suspended, , , .. , , User , .
suspended
-. , , .
, , :
User user = GetUser($userId); // unnecessary database hit? user.suspend(reason, expiryDate);
Account, User Suspension
Account
Suspension
.
, . , , , .
, , . , , suspend - , .
? .
- , "AccountAction" . , AccountAction applyTo, .
, , persitance ORM .
. OO - , . , , .
, . , , , , , , , .
, .
User:: suspend() , ( ) , . .
, , , . ? ? , //, . , . , , . , , , .
Source: https://habr.com/ru/post/1716008/More articles:how to determine what caused the close event in the jquery ui dialog box - jquery-uiFor each cycle in vb.net - foreachiteration through two sparse matrices - c ++Is it legal C ++ to use typedef in a method declaration, but a canonical type in a method definition? - c ++Where should I place the dll? - vb.netProblems with Zend Framework PDF - phpCreating sample data from existing data - Algorithm? - generatorWPF style to manage one UserControl - stylesDelete a specific line in .NET RichTextBox - c #How to find TextRange in RichTextBox (between two TextPointers) - c #All Articles