Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
It's a trade off. There is no correct answer. Sounds like its fine - apply simplest thing that works. – Dave Hillier Mar 11 '13 at 9:30
up vote 1 down vote accepted

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.
share|improve this answer

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.

share|improve this answer

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

share|improve this answer
It looks like you only read the title. – Florian Margaine Mar 11 '13 at 18:14
The whole question seems to boil down, at least to me, to the last two sentences? – Jonathan Rich Mar 11 '13 at 18:18
I don't know, I expect answers on to be more detailed – Florian Margaine Mar 11 '13 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. – David Grant Mar 12 '13 at 14:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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