Quick search:


How to keep your genereric code separated from application code

The first thing you can do of course, is put generic classes in a specific class folder separate from the application class folders. Then either subclass application specific classes from them or instantiate them from the application specific code and delegate to the instances.

In some cases you may want the framework to include and instantiate your generic classes automatically. This will for instance be the case with generic page and part classes. The framework will only automatically include them if they are either in the root classFolder or the application classFolder. Here you will have to choose: add your own generic class to the root classFoder, or create subclasses for each application that inherits from an abstract superclass you can put in your own folder. Out advise is to choose the solution with the least duplicate code.

Your application will probably not only use its own classes, but also some of the predefined concrete subclasses defined by the phpPeanuts framework. See how to keep your own code separated from framework code.

If you put a concrete subclass of a framework class in an applications classFolder, you can not make it inherit from the class with the same name in the root classFolder. If you need such an application specific superclass to inherit from your own superclass, you can put your own superclass in between the framework superclass and the concrete subclass. 

If you create an intermediate superclass you may consider the pattern of combining code maintenance schemes: Give your own abstract superclass the same name as the concrete one, with a prefix, and it will be easy to know what is its role in the code maintenance scheme. Subclass the other concrete subclasses with the same name from the new abstract superclass and you have your own code maintenance layer for generic code.