0

I am trying to tinker with the MVC pattern and I have a problem when trying to design the MVC structure. I need a model for products, however as I need to manage more and different data, I can help but wanting to create more models. Would be correct having the following structure or I am not using the design pattern correctly?

/
 app.py
 controller.py
 view.py
 models/
 model1.py
 model2.py

Or should I just have one model.py and add in there all the classes that I need?

Thank you.

asked Nov 8, 2022 at 18:45

1 Answer 1

1

The MVC pattern is usually presented with one controller, one model and several views. This is a simpflified overview:

  • The model component is generally made of many different classes and sometimes even several sub-models.

  • The original MVC was planned for groups of controller+views to be related to several models.

So there is nothing wrong with considering several models or several model files.

How you organize your source code files is orthogonal to the architecture. At one extreme, you could have all your components in one file, which I wouldn’t recommend. At the other extreme, you could have a separate file for every class (this is even required in some languages) and group files in sub-directories, for example by component. So your approach is perfectly fine.

answered Nov 9, 2022 at 6:56
1
  • Thank you so much for your answer, it really helps! Commented Nov 9, 2022 at 12:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.