0

My question is about a design related problem.

Below is the class diagram, which is close to a MVC model. Basically the View owns a DataContainer. The DataContainer has many different kinds of Data (Data1, Data2, ..). It also has a DataModifiable. The DataModifiable is actually modified during time by ModifyingThread. The ModifyingThread is created by the View class.

       View -------  ModifyingThread
         |                 |
         |                 |
       DataContainer       |
       |       |     \     |  
       |       |      \    |
    Data1    Data2     DataModifiable

The DataModifiable should be read-only for the DataContainer and is writable for ModifyingThread.

Here is my question: Which class should own the DataModiable and which class should create it? Is it the DataModifiable or the DataContainer?

Abtin Rasoulian
  • 869
  • 1
  • 8
  • 11
  • 1
    That's an answer I posted a week ago. http://stackoverflow.com/questions/24572867/using-mvc-mvp-for-swing-ui/24573281#24573281 – Stelium Jul 10 '14 at 19:43
  • 1
    And if you want detail check this http://stackoverflow.com/questions/3066590/gui-not-working-after-rewriting-to-mvc – Stelium Jul 10 '14 at 19:44

1 Answers1

0

Normaly in MVC

The view is owned by the "parent view" and register some of it's input onto a Controller so that it can and will ONLY fire Events, on which the registered Controller will react if able to.

That Controller, owns the DataModel and depending on the event received from the view, will apply a function onto the model or onto it's internal state.

The model normally does not communicate much with the controller, but the "event system" can be use so that the Controller does not have to query the model every X sec to be certain of it's state.

So from what I understand in your diagram, DataContainer is your controller and should own your DataModifiable.

BUT you should have changed your Modifying Thread so that it calls function on the Controller(DataContainer) and not directly on the model (DataModifiable)

Doing so would result in some pretty clear MVC, you could also rename your class so that only by reading the class name we know which part of the mvc it is.

++ You should not launch a new thread from inside a view class, the view class should launch a RequestEvent for it and you should have a Controller - ThreadController that will do the job for you. It would also allow you to keep an handle on that thread and have a class to manage it properly . View part of MVC is not supposed to do that for some good reason... IE MVC lol

Fawar
  • 735
  • 2
  • 11
  • 32