How To Share Code Between Applications - Mach-II/Mach-II-Framework GitHub Wiki
- Introduction
- What is the core of an application?
- What should you include in your core base application?
- Should I override or extend?
- Conclusion
If you are looking to develop an application that will feed multiple sites/applications with data, it is important to have the right architecture to take full advantage of code re-usability and make your applications more manageable and scalable. For example, a blogging engine is much easier to build with a simple re-skinning feature because each blog implements the "same" basic features. However, this isn't the case whenever you want SiteA to behave one way, but SiteB behave in another way. Although, both SiteA and SiteB may share most features and functionality they most be able to provide the flexibility to customize the behavior.
The core of an application could be the part of the code that is shared(i.e. listeners). Whether or not all applications will use all of them all the time doesn't matter. Core could also mean that all applications should implement certain view pages by default. This doesn't mean the core application provides them, but thinks the .cfm files should be available (i.e. each application implements its own version).
You must figure out where you can break your application into a core "base" application. To do this, define which are the common features and functionalities that will be used in each site and separate those functionalities into their own config file.
Look at this code:
<mach-ii>
<includes>
<include file="/mach-ii_core.xml"/>
<include file="/mach-ii_example-com.xml" override="true"/>
</includes>
</mach-ii>
The base config file is nothing more an that a giant mixer. You include the core functionality with the first include and the customizations for example.com in the second. Notice the override attribute. Without it, Mach-II would throw exceptions if say both includes contain a definition for a listener named "sample".
TODO
TODO - Needs sample code