Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That sounds like Allen Holub. One might argue that constructors are <em>evil</em> solely to drive web traffic :) They are no more evil than any other language construct. They have good and bad effects. Of course you can't eliminate them -- no way to construct objects without them!</p> <p>What you can do, though, and this is the case that Allen was making, is you can limit your actual invocation of them, and instead favor, when sensible, factory methods like your <code>Initialize</code>. The reason for this is simple: it reduces coupling between classes, and makes it easier to substitute one class for another during testing or when an application evolves.</p> <p>Imagine if your application does something like</p> <pre><code>DatabaseConnection dc = new OracleDatabaseConnection(connectionString); dc.query("..."); </code></pre> <p>and imagine that this happens in a hundred places in your application. Now, how do you unit test any class that does this? And what happens when you switch to Mysql to save money?</p> <p>But if you did this:</p> <pre><code>DatabaseConnection dc = DatabaseConnectionFactory.get(connectionString); dc.query("..."); </code></pre> <p>Then to update your app, you just have to change what <code>DatabaseConnectionFactory.get()</code> returns, and that could be controlled by a configuration file. Avoiding the explicit use of constructors makes your code more flexible.</p> <p>Edit: I can't find a "constructors" article, but here's his <a href="http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html" rel="nofollow">extends is evil</a> one, and here's his <a href="http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html" rel="nofollow">getters and setters are evil</a> one.</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