Abstracting as much as possible can insulate you from framework problems.
I'll give you an example. I've started working with Codeigniter a lot lately. I appreciate some of the stuff the framework does, but I'm not a fan of other aspects of it. One particular thing I don't like is that you pretty much have to use a separate copy of CI for each application you write. If CI comes out with a newer version, I have to go back and upgrade multiple apps.
Because of this, I created a separate directory called "base" in my CI installs, and set up a PHP autoloader to be able to load classes from it. I have things like "Base_controller", "Base_service", "Base_model", etc., and I use this across all my CI installs. These classes extend the normal CI classes, and in turn my applications extend these base classes. For instance, in App number one, rather than write a Controller class that extends Codeigniter's Controller
class, I extend my Base_controller
, which in turn extends the CI Controller
.
This gives me one level of separation between CI and my apps. If CI ever changes, I should be able to manage it by upgrading just my "base" layer. I can also have a lot of base functionality in this layer and only write it once, rather than extending a new install of CI each time.
Abstraction requires careful design, as you don't want to go overboard with it. But it's definitely a useful tool to separate your code from a framework's code.