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.

    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.

    1
    • Thank you so much for your answer, it really helps!
      – Eideann
      CommentedNov 9, 2022 at 12:59

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.