On 30 June 2016 at 00:53, sebb <[email protected]> wrote:
> As the subject says; the two factories use a different naming convention.
>
> Would it be sensible to standardise on getInstance, given that the
> class name says what the instance will be?
Hm, but CryptoRandomFactory.getCryptoRandom() returns a CryptoRandom,
and CryptoCipherFactory.getInstance() returns a CryptoCipher() (not a
CryptoCipherFactory).
I think it would be misleading to call it getInstance() as that
implies the singleton pattern, e.g. to return the *Factory, but in
fact neither of the factories can be instantiated (private
constructor, only static methods).
Both methods take parameters, so it would be returning different
instances depending on the parameters - so although the ciphers etc.
might always be the same instances, it's not the singleton pattern.
(But then not quite the factory pattern either :) )
Agreed that the two factories should however be consistent, so I would suggest:
public class CryptoRandomFactory {
public static CryptoRandom getCryptoRandom( .. ) { .. }
}
public class CryptoCipherFactory {
public static CryptoCipher getCryptoCipher( ..) { .. }
}
But I understand your argument.. because for the caller it will be
quite repetitive:
CryptoCipher cryptoCipher = CryptoCipherFactory.getCryptoCipher( .. ) ;
CryptoRandom cryptoRandom = CryptoRandomFactory.getCryptoRandom( .. ) ;
Perhaps just call the methods just .get(...) instead?
public class CryptoRandomFactory {
public static CryptoRandom get( .. ) { .. }
}
public class CryptoCipherFactory {
public static CryptoCipher get( ..) { .. }
}
--
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons
http://orcid.org/0000-0001-9842-9718
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]