Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

orest's avatar
Level 13

avoid making User a god object

My main concern is to find a way to avoid to add every new feature as a method in the User model, because it can become huge.

For example

$user->like($post)

$user->subscribe($post)

And the list goes on.

I watched a video where Adam Wathan was explaining that a method name should describe

  • what you can do to the object
  • NOT what an object can do

Taking the aforementioned examples, according to Adam

$post->like($user)

$post->subscribe($user)

And I have to say that this looks nice, and it helps to prevent making the User model a god object.

However, there are cases that this approach can be confusing.

For example, when a user wants to follow another user

$John->follow($doe);

In this example, following Adam's approach, Doe started following John and not the other way around, which is confusing.

Another approach can be to use past tense and maybe even use by in method names to make it even more clear, for example

$post->liked($user); 
$post->likedBy($user);
$John->followed($doe);

This can still be confusing so maybe using also the by word would be more clear.

$John->followedBy($doe);

What are your thoughts on this ?

0 likes
2 replies
martinbean's avatar

@orest I personally just go for what’s actually readable instead of worrying about it becoming a “god” object.

In terms of users, if they’re a core part of your application then yes, they can acquire a lot of methods. But in the above examples, I’d break “categories” of methods into traits. So my user model might have traits called CanSubscribe, CanLike, etc.

1 like
orest's avatar
Level 13

That is also an option which i like, because readability is important, but i was trying to balance between readability and avoiding god User.

Do you have a limit on the number of traits ?

Where you would say "i have too many traits, maybe i should do something else"

I have currently 6 traits on the User model and i've been trying to follow Adam's approach

Please or to participate in this conversation.