java - Model shared between two objects -


I have three squares that are interacting in an interesting way. There is a model class, and it has to be used by both of the other classes, so an example of this is kept as a member of each. These two classes interact with the model in different ways.

There are some instances where the model object is to be completely thrown out and replaced with a new instance, and it makes things complicated. And these opportunities arise in both viewing / controlling classes. Therefore, one of those classes should be able to send a signal on the other, "We need to coordinate and facilitate the replacement of our model object with the new model object." Right now I have the code in class B, which tells class A to create a new model and send it back, but now I have to handle the opposite situation, where this event occurs in class A, and unfortunately there's no class A No reference

Update : Sorry, people, this can not be a singleton. Singlants occur when you are guaranteed that there is only one thing there is no relation to anything that I need anything above it.

Update : So far, in reality only an example of this ideal square, but I had a vague suspicion that I need to allow more, and I Using the singleton design pattern did not want to limit itself, when it actually resolved different concerns from me. It turns out I was right: yesterday I got a new requirement and now I need to support one of these arbitrary numbers. :) Do not limit yourself to when you do not have to, and do not misuse design patterns for situations where their purpose was not!

You want an intermediate model layer, a model "holder" object that is a two-square reference modelholder Keeps in context of the model.

This modelholder should also support the audience, so when its model is removed, it can inform any audience that the model has changed.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -