Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to figure out if this code creates any benefit by using a Singleton
    primarykey
    data
    text
    <p>I'm working on a project where one of the co-developers (and previous developers) use a Singleton/Facade for just about every page of class that has a lot of method calls inside of it, but that don't actually maintain the data.</p> <p>For instance:</p> <pre><code>public class FooFacade { private static FooFacade m_facade = null; private static DataAccessManager m_dataAccessMgr = null; public StringBuilder Status {get; set; } private FooFacade() { this.Status = new StringBuilder(); } public static FooFacade getInstance() { if (m_facade == null) { m_dataAccessMgr = DataAccessManager.getInstance(); m_facade = new FooFacade(); } return m_facade; } public void clearStatus() { this.Status.Remove(0, Status.Length); } public void Method1(string value1, int value2) { // DO SOMETHING } public List&lt;string&gt; Method2(string value1, int value2) { // DO SOMETHING ELSE // RETURN LIST } </code></pre> <p>Now, I have certain issues with the naming convention and the fact that they have the Singelton inside the same class as the Facade and the fact that the Facade isn't really a Facade. (but that's a whole different conversation).</p> <p>So my question is whether there really is a benefit from this. The best that the developer could explain is that it is better for memory management since you're not constantly creating and disposing of objects. </p> <p>Our application is not an enterprise level app and we don't have issues with memory. Anytime the site is slow, it's really due to the database and not the code.</p> <p>Thanks for your help. I'm a developer who loves to know why to make myself a better developer. Since I can't get it from the developer in words that make sense, I'm reaching out to you guys.</p> <p>Thanks, Chad</p> <p><strong>UPDATED</strong> Thanks to the comments below, I know that the status is a serious concern as it has a chance of being a huge security flaw. Is there any benefit to using this code in a Singleton when it comes to memory management, speed, etc? Or would it just be easier to instantiate FooFacade every time I need it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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