0

After making a webservice call and gathering data for your model data, i can think of a few ways to persist the model until the application process terminates:

  1. save the model as static variable so its in memory and fast to access
  2. write the model data to a DB. Access the db tables when data is needed. this is slightly slower depending on how much data your trying to get and searches.
  3. create a singleton dataModel but this is # 1. I could inject it using Dependency injection so it would not be seen as a singleton.
  4. pass the model data from class to class via parameters. this might be good for testing different model data, etc

This is all i can think of. What is the recommended way in design architecture like MVC to create a model available to the entire application?

j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • "Best way..." is usually a red flag that the question is POB. – Hovercraft Full Of Eels Oct 14 '16 at 23:29
  • 1
    What is "better", a dump truck or a sports car? Depends on if you need to haul 10 metric tons of dirt, right? You can optimize it several different ways, each design goal changes the applicability of different approaches. – doug65536 Oct 15 '16 at 01:08

1 Answers1

0

Ok, this is definitely opinion based, there are many right answers, but static variables and singletons are very likely wrong. They make testing incredibly difficult, and strongly couple your application to a single implementation.

It also strongly limits your application size to the amount of data that can fit into memory at one time.

2 vs 4 is probably where it will end up a debate between various architectures, and should probably not be discussed here.

Rob Conklin
  • 8,806
  • 1
  • 19
  • 23