Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Thanks for the answer. But if I use this approach then I will have make conditions it will be get complex if I have one more object say billing, with two states paid and unpaid. Then I will have to check like this: if ($company->canUserLogin() && $billing->canUserLogin()) { $user->state->login();} Then don't I am back to place I had started: "Remove conditions with Polymorphism".? Commented Dec 7, 2021 at 2:31
  • @MKJ, another approach is that the login blockage caused by a wrong state of billing (or the company) causes the User to go into a new state where login gets blocked. Then you transfer the if conditions into a more complex statemachine. Commented Dec 7, 2021 at 7:03