Bird
0
0

You want to add a new service method create_user that saves a user and returns the new user ID. Which approach best follows the service layer pattern in Flask?

medium📝 Conceptual Q15 of 15
Flask - Ecosystem and Patterns
You want to add a new service method create_user that saves a user and returns the new user ID. Which approach best follows the service layer pattern in Flask?
AAdd create_user method in service class and call it from route
BWrite database code directly in the route
CPut user creation logic in app initialization
DUse global variable in route without service
Step-by-Step Solution
Solution:
  1. Step 1: Recall service layer purpose

    The service layer should contain business logic like user creation, keeping routes simple and clean.
  2. Step 2: Evaluate options

    Add create_user method in service class and call it from route correctly adds create_user to the service class and calls it from the route, following the pattern.
  3. Final Answer:

    Add create_user method in service class and call it from route -> Option A
  4. Quick Check:

    Business logic in service, routes call service [OK]
Quick Trick: Put business logic in service, call from routes [OK]
Common Mistakes:
MISTAKES
  • Putting logic directly in routes
  • Using global variables instead of service
  • Placing logic in app initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes