Reputation: 2074
I am wondering about best practices here.
MVC (Model - View - Controller) patterns involve separating components of your program that model the data, manipulate those models, and display those results to the user (usually through the UI) in some way.
What about a function that takes the model data and inserts it into a database? For example I have an object called a GameBoard, and I also want the ability to insert the state of this board into the SQL database for storage / historical purposes. I have a class that holds all my query functions. I am not asking where to store the query calls themselves -- again those are all encapsulated in one class.
But where would I call these functions from? Would this sort of functionality make the most sense to make it as a method of GameBoard? Or should it be part of the controller classes?
Upvotes: 2
Views: 184
Reputation: 11619
In ideal world, class that performs GameBoard state persistence should listen to game events:
When user clicks UI button to update view with database data:
next 3-4-5 steps are the same
Upvotes: 1
Reputation: 839
Following are the points for MVC.
where would I call these functions from?
You should call these functions from your domain model (model).
Further Reading martin fowler
Upvotes: 0
Reputation: 51433
But where would I call these functions from?
In the controller. Usually the controller has dependencies to model objects for input and outout. E.g.
Depending on your architecture you might introduce an application service below the controller.
Details at https://www.link-intersystems.com/blog/2013/07/20/the-mvc-pattern-implemented-with-java-swing/
Upvotes: 1