How to implement an MVC pattern without saving views

I would like to implement the MVC pattern in a difficult situation. The difficulty is that my models (objects generating events) are durable, and Views (event receivers) are short-lived. My problem is that thanks to the connection between them, long-lived models keep my short-lived looks alive, i.e. They cannot collect with garbage.

  [MODEL] ------- <weak> -------> [VIEW]
     |
 <strong>
     |
     v
[CONTROLLER]

A way around this is to save the connections in the model in the WeakHashMap & View, Controller> file. This essentially allows you to view the type of garbage, and when that happens, WeakHashMap will also throw out the appropriate controller. That is, if the Controller does not contain a (strong) reference to the view, what it usually does. In this case, the views are kept alive through strong links until the model goes beyond.

  [MODEL] ------- <weak> -------> [VIEW]
     |                               ^
 <strong>                            |
     |                               |
     v                               |
[CONTROLLER] ----------- <strong> ---/

Is there any other way to connect listeners to my models that will not contain my views (and controllers)?

: mdma: , . , , View, Controller View.

+5
4

MVC.

  • , . , - .
  • , . , - .
  • . . , , - .

, . , . , , . .

MVCP:

  • . . , . , Presenter. , .

- , , . . , , : Presenter.PopulateWith(model, controller). ( , . ..) . !

MVVM, WPF. Java, . , . .

+3

MVC. , .

0

, . :

  • , , .

  • . WeakReference, , , , , . ​​( ), no-op.

0

... , View, Controller View.

... .

Model Controller, Controller , , View . Controller View ... Model .

, (*), .

.

(* , , , ... , . , , Controller , , , Field, null.)


EDIT

, JLS - JLS 15.9.1

(§8.1.1.1). (§8.1.3); (§8.1.1, §8.5.2). (§8.1.1.2).

OP...

0

All Articles