Python Forum
Replacing model in MV(C) application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replacing model in MV(C) application
#1
I am building a program using what is hopefully an MV architecture (see example below).

The main data structure in my program is bound to a number of views, and observed by a number of objects. I am confused at what is the best strategy to completely replace the data I am working with (new file load for example).
Should I be working with the same instance and clear and replace the data within the object (meaning that if an error occurs it may be complicated got back to the previous state)
or should I create a new instance and somehow transfer the bindings from the old instance to the new? (I don't see a simple and clean way of achieving this)

any suggestions?

The models are based on the class below:
class Observed:
    def __init__(self):
        self._observers = []
        self._mutex = False

    def attach(self, obs):
        if obs not in self._observers:
            self._observers.append(obs)

    def detach(self, obs):
        if obs in self._observers:
            self._observers.remove(obs)

    def notify(self, event):
        for obs in self._observers:
            obs.handle_event(event, self)
the views implement the following methods
class View:
    def bind_model(self, model):
        self.model = model
        self.model.attach(self)
        # do update

    def handle_event(event, origin):
        # do whatever
Models are bound the following way, possibly to multiple views.
model = Observable()
view1 = View()
view2 = View()
view1.bind_model(model)
view2.bind_model(model)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  model.fit and model.predict errors hatflyer 6 1,198 Nov-10-2023, 01:39 AM
Last Post: hatflyer
  How to send data from a python application to an external application aditya_rajiv 1 2,132 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles Anldra12 10 5,680 Jun-11-2021, 04:48 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020