Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The usage of static is often frowned upon from an OO design perspective because it gives tight coupling between objects. With statics methods it’s impossible to decouple an interface from its actual implementation. This lack of decoupling can for example become a problem when you want to unit test a single class, as it can’t be separated from the other static parts.</p> <p>In today’s Java landscape you’re singleton crypt class can be much better designed with the help of <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow">Dependency Injection</a> (DI). The ProcessCommonBase could also be implemented as an DI singleton if it didn’t had that very strong code smell, because if it’s a <a href="http://en.wikipedia.org/wiki/God_object" rel="nofollow">god-object</a> then it should be refactored, for example by using DI for injecting properties into you crypt class.</p> <p>Example code based on Google Guice:</p> <pre><code>@Singleton public MyCrypt { private final key; @Inject MyCrypt(@CipherKey String key) { this.pBase = pBase; } public synchronized String encrypt(String someTextToEncrypt) { /*encrypt algorithm*/ return encryptedForm; } } </code></pre> <p>Configuring DI properties:</p> <pre><code>public class PropertiesModule extends AbstractModule { @Override protected void configure() { String key = .. what ever .. bind(String.class).annotatedWith(CiperKey.class).toInstance(key); } </code></pre> <p>More DI examples can be found here: <a href="http://java.dzone.com/articles/cdi-overview-part-1" rel="nofollow">http://java.dzone.com/articles/cdi-overview-part-1</a></p> <p>Populair Java DI implementations are: <a href="http://code.google.com/p/google-guice/" rel="nofollow">Guice</a>, <a href="http://www.springsource.org/" rel="nofollow">Spring</a> and <a href="http://www.oracle.com/technetwork/java/javaee/overview/index.html" rel="nofollow">Java EE6</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