I'm working on a Java-based library which makes use of PKCS #10 requests. There are PKCS #10 libraries available for Java (Sun and IBM libraries that come with the respective JDKs), and the open-source Bouncy Castle library.

I'd rather not couple my library to another through the API, so my initial thought was to create a wrapper. However, PKCS #10 is potentially complex, so the scope of the wrapper would expand quite quickly, and users of that wrapper would probably "unwrap" the wrapper and use one of the aforementioned libraries for any heavy-lifting, particularly if they use PKCS #10 in their own applications already.

My remaining option is to provide a simple wrapper around a byte array. Is providing a very thin wrapper just for the sake of typing good practice?

  • It's a trade off. There is no correct answer. Sounds like its fine - apply simplest thing that works. Mar 11, 2013 at 9:30

3 Answers 3


As Dave said in the comments, there's always a tradeoff.

I see a few points in favour of your approach:

  • It's self-documenting: void AnswerRequest(CertificateRequest request) might be more descriptive than void AnswerRequest(byte[] request).
  • You will probably create a few methods that operate on the byte[]. They might fit nicely as instance methods on your wrapper class: request.getPublicKey() is nicer than Pkcs10Tools.ExtractPublicKey(requestByteArray).
  • Information hiding: If you ever decide to change the internal representation of the class (e.g., by adding fields to cache certain values extracted from the byte array), you can do that without changing the code using the class.
  • It's extendable, if you decide to go from a simple wrapper to a more advanced class.


  • If most of the work is done by external libraries, the consumers of your class will be using new CertificateRequest(myByteArray) and request.getByteArray() a lot.

Yes, this is a good practice, because it gives meaning to those wrapped bytes by introducing a user interface. You also have the option to make using those bytes correctly more easy, because the API is a hint on what can be done with them. Just using plain bytes may lead to a smell called primitive obsession.


Yes, it's a very good practice - you're leveraging the biggest strength of statically typed languages.

  • 1
    It looks like you only read the title. Mar 11, 2013 at 18:14
  • The whole question seems to boil down, at least to me, to the last two sentences? Mar 11, 2013 at 18:18
  • 1
    I don't know, I expect answers on programmers.se to be more detailed Mar 11, 2013 at 18:26
  • Jonathan: I was trying to give background to the question, i.e. I would usually create a wrapper, but it doesn't seem appropriate for the reasons given. Mar 12, 2013 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.