C ++ MVC Model - How to implement it?

I am a bit confused as to how the model should "work" in my basic C ++ implementation, and more specifically, how the data from the database should be encapsulated / processed.

My thoughts at the moment relate to the model, for example, to the static method findById (), which will return an instance of the same model, which then will be a single "row" of data (allowing manipulation, etc.) to be a suitable approach.

In terms of creating a new row in the database, I assume that a new instance of the model will be created, filled with data, and the save () method, which is called?

Hope I'm on the right track, but I'm a bit confused about implementation / design.

Any advice is appreciated.

Thanks in advance James

+5
source share
2 answers

So, I think you are asking which interface would be suitable for "translating" between a relational database and an object-oriented application, especially in the context of an MVC application written in C ++.

The general approach is called object-relational mapping, or ORM . I only know how Ruby on Rails implements ORM, but if you port it to C ++, it looks like this:

  • Database table mapped to class
  • Table operations (for example, queries) are mapped to static member functions of the corresponding class
  • Rows in the table correspond to instances of the corresponding class.
  • -

, ++ ORM. , ++.

: ORM ++.

+4

: " " - Gamma et al. MVC : observer.

.

: . . . , ( , , qt). . ( ). . . , (, , , ).

: lern Smalltalk (, Cincom Smalltalk).

+1

All Articles