The real title of this post, appropriately enough, is 'Endless Torment, or Unbelievable Terror'.
I'm currently in the process of writing a full-fledged online school based on a telegram bot. Accordingly, the problem of dividing users into roles arises. I have, for example, tutors and students.
EXAMPLE OF METHODS OF MENTOR CLASS:
*Тыкни чтобы посмотреть картинку*
EXAMPLE OF METHODS OF STUDENT CLASS:
*Тыкни чтобы посмотреть картинку*
Both classes inherit from the main class 'User'. As you can see, the methods of the classes are similar to each other in name and content.
In the course of writing the system, situations like this arise (quite often):
*Тыкни чтобы посмотреть картинку*
Personally, it just fucking hurts my eyes. I thought there are two ways out of this idiotic situation:
> Continue to creating functions: like create a function that will call one of these two functions based on the role. (but it cuts my eyes no less).
> You can combine two functions into one, pass the role to it, make it for the parent class and brrrrr. fuck. I don't want to do that, because it's a complication.
But as it turns out, there is such a thing as getattr in python. And it's a fucking lifesaver.
*Тыкни чтобы посмотреть картинку*
I'm currently in the process of writing a full-fledged online school based on a telegram bot. Accordingly, the problem of dividing users into roles arises. I have, for example, tutors and students.
EXAMPLE OF METHODS OF MENTOR CLASS:
*Тыкни чтобы посмотреть картинку*
EXAMPLE OF METHODS OF STUDENT CLASS:
*Тыкни чтобы посмотреть картинку*
Both classes inherit from the main class 'User'. As you can see, the methods of the classes are similar to each other in name and content.
In the course of writing the system, situations like this arise (quite often):
*Тыкни чтобы посмотреть картинку*
Personally, it just fucking hurts my eyes. I thought there are two ways out of this idiotic situation:
> Continue to creating functions: like create a function that will call one of these two functions based on the role. (but it cuts my eyes no less).
> You can combine two functions into one, pass the role to it, make it for the parent class and brrrrr. fuck. I don't want to do that, because it's a complication.
But as it turns out, there is such a thing as getattr in python. And it's a fucking lifesaver.
*Тыкни чтобы посмотреть картинку*
READ OTHER POSTS