concept generic interface in category php

appears as: generic interface, The generic interface
PHP in Action: Objects, Design, Agility

This is an excerpt from Manning's book PHP in Action: Objects, Design, Agility.

But there is one more consideration: in Uncle Bob’s terminology, we’ve now taken the first bullet. We were cruising happily along, using PHPTAL templates for all our web pages, and suddenly someone hits us with the requirement to use Smarty instead. We know now that a certain kind of change can happen: switching template engines. And if it happens once, it could happen again. So what we probably want to do is to protect the system from further changes of the same type. The way to go in this case would be to move toward a generic template interface, which would not be identical to either the PHPTAL interface or the Smarty interface. The generic interface should be as easy as possible to adapt to a new template engine. In other words, it should be easy to write an Adapter that has the generic interface and delegates the real work to the new template engine.

So far, we have at least some indication of what’s needed for a generic TemplateAdapter interface. It will need to have an interface that re-creates the functionality of both the PHPTAL and the Smarty objects. We don’t want to have to use fancy tricks such as the Context object. So the interface should have a method to get variables. It should also have a display() method. And the need to convert the template name is a tricky thing that needs to be smoothed over. If we assume that the template only needs a single template file name in some form, the generic interface might just require the file name without the extension and add the extension automatically.