How to make memory-efficient code, but still have all the possible code nicely encapsulated ?
I have a feeling that the OO (object oriented) approach is more intuitive and the code is nicely organized and encapsulated, but it can use a lot of memory, because there are usually many live object instances in the memory.
In contrast, the MVC (controller, model (database)) approach code is much less encapsulated but uses much less memory, because the objects in memory are only when some client asks for them, and then they are disposed.
I need to make an internal health monitoring system, to periodically ping ip cameras. There will be about 10,000 items (cameras) to monitor, with a boolean state - Good / Bad.
If I go the OO way - I will hold a class for each of the item, with its ping result, timer, events to notify some other items. So I will end up with 10,000 instances in memory all the time. There is not much, but what if there were 100,000,000 items. I prefer this way, because it is intuitive and I have a perfect (encapsulated) place for any code I may need to run in the concrete item class (timers, events, handlers, subscriptions).
If I go the MVC way - I will hold all the data in database, so the memory usage will be minimum. But I will have to improvise a way to trigger code execution, like periodic timers, events, handlers, subscriptions. And that code - where will it be written? Will it be nicely encapsulated? Also, what code will call those triggers? Will it also be encapsulated? For example, I can make a timers engine, and hold a dictionary of timers for each of the 10000, but then the code will not be encapsulated.