Let's assume we have a class structure for a particular application (a University manager for example, with classes representing semesters, subjects, timetables and so forth). It is to be a desktop application (WinForms for instance), with data being held in an Sqlite database backend. The schema for this database is based on the UML class diagram, with classes being mapped to tables, class attributes mapped to table fields, and many-to-many relationships represented by link tables.

I understand that the Model should manage all the rules and logic of the application, and contain all the data. What would be the best way to manage displaying this data (for example, displaying a list of all classes available in a particular semester in a suitable UI control in the appropriate form, and to enter data (creating a new student profile). Should the appropriate data be fetched from the DB and placed into instances of the objects, which are then used to fill out the fields in the UI widget? the same goes for inputting data. For example, when creating a new student profile, should that data be used to create a student object, which is then used to fill in the appropriate DB table?

The core of the question is, was the effort of designing the class structure with CRC methods and creating a UML diagram a wasted effort? Is the class structure redundant, since the data can be placed into the DB or retrieved from it without this class structure? The Model would function as a means of executing queries to achieve this, based on commands from the controller.

有帮助吗?

解决方案

In an MVC the Model is not a database. MVC is a pattern to split the concerns and responsibility of the UI, and you can have a UI CRUD build with the MVC pattern without a database. The data could be stored in memory or some backend using REST API calls.

The class structure is not redundant with the database because the way you store your data should not be coupled with the design of your system. Although people tend to reflect the UML diagram in the relational database you can not do that with other types of databases like a document or key-value databases.

许可以下: CC-BY-SA归因
scroll top