Would you wrap PDO or expand it?

My question is pretty clear and I really would like to hear some reasons for the answer.

Additional Information:

  • I do not use any PHP frameworks.
  • PHP> 5.3.

Update:

Now I do not have a lot of restrictions on my project, this is a project of one person, and I worked hard to make everything as tight and modular as possible. as I was told, I did not like the PDO API after playing with it for a while, but this is not a big problem if you stick to it. The Public API will give me more flexibility or is considered good practice.

So my question is: what would you win and lose using composition or inheritance, considering the object in question, is it the level of abstraction, PDO in this case?

tl; dr: a project of one person who is trying to be as modular as possible, composition or Inheritance to use a third-party abstraction layer (PDO in particular)?

Note: if this is not the place, vote to go to Programmers. and sorry for my bad english.

+6
source share
2 answers

I am a fan of packaging for third-party classes in such a way that you are much less dependent on class support. If someone later changes the function names in the PDO, your code will change around all of your code. When packaging, only the packaging class will change, since your interface will be independent.

+5
source

I wouldn't wrap it at all if you don't like the API. If you decide to go down this route, I would use Idiorm (and possible Paris for active recording), instead of rewinding my own.

I would never have thought of extending a third-party extension if I had not planned to maintain its code, or had never updated this library. By wrapping, you isolate the third-party library from your code as much as possible so that you are less affected by changes in their code.

+3
source

Source: https://habr.com/ru/post/905502/


All Articles