Multiple Models in an MVC? How should I make them?
I'm wondering the correct way to deal with an Array of models. My models are basically accounts, with a name, id, and balance. I need to make as many of them as are in a file that I have.
What I originally did was just create a (Model models) in my controller and did the file input in the controller, just directly creating all the models there and then sending them around to the various view and other functions. This sticks-and-glue method worked, and I completed the program, but now I'm trying to re-use it with expanded functions and my little card castle of hope has crashed down and I need to redo the structure.
Do I create an AddAccount method in the model class to read in one line from a file? How do I keep all my models together? I am so confused about this that I can't even really ask a proper question about it.
Re: Multiple Models in an MVC? How should I make them?
I think you may have confused your terminology somewhere.
Your code has a model.
It may have many parts, and there may be many instances of those parts (eg your Accounts), but it just a model.
Having a class called 'Model' seems wrong. If it's an account, then it should be called Account.
In any case, your model should not care particularly where the data for it comes from.
That's part of the Controllers job.
Part of the Controller will be for reading in your model and manipulating it.