D
D
dev4002016-09-29 00:41:04
PHP
dev400, 2016-09-29 00:41:04

What's the best way to break the logic?

Let's say we are talking about authorization, which includes login, registration, and password reset. Are these 3 parts described in separate classes, or methods in one class? Trying to understand SRP

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2016-09-29
@dev400

Trying to understand SRP

Let's think. Here you have a class that:
- deals with user authentication
- deals with user registration
- deals with password recovery
There are three usage scenarios, three areas of responsibility. Moreover, each of these features can be implemented separately from each other, tested separately from each other, and changes can be in each of these things.
On the other hand, let's think further. If we place all these operations within the framework of the user, then, as it were ... everything is cool) the user can change his password, the user can log in, and registration is just creating a new user. That is, from the point of view of OOP, everything is cool, and we do not need to break the user's encapsulation. Yes, the user will be able to do a lot of things and maybe even know about something that he doesn’t really need to know about - but this is already being solved by dependency inversion and delegation.
Let's think further... for example, the same registration at least requires a separate class that will contain the registration logic. In addition to creating a user, we need to send him an email, and perhaps do something else.
ps little stuff: https://gist.github.com/fesor/33f041e3f362beff8d0e...

V
Vladislav, 2016-09-29
@RGV

Does it make sense to produce classes just for the sake of strict adherence to SRP?
Try to implement both options and figure out what will be more convenient to work with in the future.

H
he he, 2016-09-29
@tosha_lol_daaa

Trite: AuthController where the necessary methods exist (but I would put "password reset" in a separate controller)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question