Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Having a singleton at all may be a wrong move. There are times that a singleton is appropriate, but there's usually a better choice.</p> <p>It sounds like you may already be implementing something resembling the <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow">Model-View-Controller</a> pattern, which would be appropriate. In this context, this array of measurements is part of your model, and it may make sense for it to be a separate class, but there's likely no need for it to be a singleton.</p> <p>The name <code>MeasurementsArray</code> is implementation-specific. I would be more inclined to call it just <code>Measurements</code> or to give it a name reflecting what the measurements are measuring.</p> <p>In fact I wonder about the name of your <code>Measurement</code> class. What is it measuring? What does it actually represent? </p> <p>If you post some code, we might be able to provide more specific ideas. </p> <p>Based on your update and a bit of thinking, you might want to think about <a href="http://martinfowler.com/eaaCatalog/repository.html" rel="nofollow">The Repository Pattern</a>. Rather than having your controllers hold the array, they have access to the repository from which they can get it.</p> <p>My thinking here is that your array of measurements might be supplied by a <code>MeasurementRepository</code> and that while now the data might be a single simple array that the repository just holds, it might evolve to something that is stored in a database per user and with variation over time, so that your repository supplies more complex access.</p> <p>Rather than having this repository be a singleton (though that is certainly sometimes done), it might better be just created once and then injected into everything that needs it. See <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow">http://en.wikipedia.org/wiki/Dependency_injection</a> and <a href="http://butunclebob.com/ArticleS.UncleBob.SingletonVsJustCreateOne" rel="nofollow">Uncle Bob's blog</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload