MFC Document / View Dilemma

I have a situation where it is not clear whether to use the document or the view. I think I must split the solution between the two, and MFC makes such things quite complicated.

I am reading a file that has many record formats, and showing them in a CListView. I also need to show each record in a custom form when the record (row) is selected.

I have about 50 record types and I am likely to have about 100 total. I have a base class and I derive a class for each type of record. Each class has a virtual function for reading each type. Those classes are in the document of course.

MFC is designed such that the document does not call the view directly; we normally use UpdateAllViews instead.

Each record type has a record type code that is stored with the data. So as best as I can think, when a row (record type) is selected, I can get a pointer to the instance of the corresponding document object from the list control's data for the row (assuming I put it there). Then in the document I call a virtual function that calls UpdateAllViews to access the view for the specific record type. Then OnUpdate can use an array of functions (instead of a big switch) to do the custom UI processing. I have not thought about it a lot, but I probably could create a UI base class with derived classes for UI processing of each, but if I do then I have not yet figured out how I would get C++ to relate the document objects to the UI objects.

Fortunately I don't need to provide editing capability.

Comments on simpler solutions are appreciated; sample code is not necessary.

 


Update: I will probably create UI classes in the view and just use the data from the document.



Answer this question

MFC Document / View Dilemma

  • Greatestevil

    Yes, I did use the simpler solution, thank you.

    MFC's document / view architecture makes many things quite complicated but I do try to conform to the philosophy when possible. Keeping the logic in the UI is much simpler and I think is a valid use of the document / view architecture.


  • Hokgiarto

    "Update: I will probably create UI classes in the view and just use the data from the document."

    I assume that you already went ahead with the above solution.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • MFC Document / View Dilemma