Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Someone proposed to me this pattern which I have never heard of before and can't find any information on it.

The basic idea is, when building a library for other developers to use; if the developer includes my library along with a 3rd party library the behavior of the API calls to my library changes.

An example:

  1. I have a library/API for inserting, getting, updating, deleting on a database.
  2. Developer includes a 3rd party database encryption library.
  3. My library/API changes to require a "unencrypt(password)" call to be made before inserting, getting, updating, deleting.

Is this a safe practice? Is there anything else out there like it? What advantages and disadvantages are there to this pattern?

share|improve this question

1 Answer 1

Essentially what you are saying is that you'd like to design your library to have a dependency on a third-party library, and fall back to some default behavior if that third-party library is not available.

I think this is perfectly acceptable as long as it is well-documented.

If you are asking whether it is acceptable for an API call to do two entirely different things, I would say no. The meaning of the API call should not change depending on the presence of another library.

share|improve this answer
    
Agreed. Whether the implementation of the API call uses an internal mechanism or calls out to the 3rd party lib, the API call should honor its contract. –  Mike Partridge May 21 '13 at 17:06
    
It would also be a good idea to log whether the internal or external mechanism has been chosen. –  Mike Partridge May 21 '13 at 17:17
    
Thanks for the responses. An example I have is; 1) My API has methods for acting on a database. 2) Include a 3rd party library for encrypting databases. 3) Suddenly my API methods for insert, get, update, delete require a "unencrypt(password)" call to be made. To me this seems similar to the second point you made, where the API does slightly different things. –  C Nick May 21 '13 at 18:34
    
In your case I think that your library should be encryption agnostic, and let the developer handle encrypting/decrypting and locking/unlocking. I don't think it would benefit the developer to have this managed internally. –  M. Dudley May 21 '13 at 20:00

Your Answer

 
discard

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.