Is it right that part of the business logic remains in the controller?

having a simplified class like this that governs a quiz game:

class Game():
def __init__(self,username):
    ...
    self.username=username
    self.question_list=db.getQuestions()
    self.game_over=False

def get_question(self):
    ...
    if self.question_list.is_not_empty():
        return question

def check_answer(answer)
    ...
    if answer.is_correct():
        self.game_over=False
    else:
        self.game_over=True

and having a web controller that receives input parameters such as username, questions and answers. Is it right to use the Game class directly from the controller?

I ask this question because, looking at the controller code, I feel guilty to encode inside some logic; for example, the controller starts the game only when the username is received, and then calls get_question and check_answer in order.

Do you think it is more correct to have another "layer" that receives input parameters from the controller and directly talks to the Game class?

Thanks michelle

+3
2

, .

, , . , - .

get_question check_answer, , , . , , .

, , , - , , , , -, , , , .

+3

. . .

0

Source: https://habr.com/ru/post/1731672/


All Articles