Saturday, September 27, 2008

application structure: classes

I thought i'd take a break from nominals and the like as I have been thinking about how to make this an app that developers can contribute to. Also, I have been thinking about how to create the different sections (sales, purchases, etc.) and how to integrate them together so that they can share common data and functions easily.

Then it hit me: class extension. Its still a new concept to me but, (and correct me if i'm wrong,) you can have a base class that others "extend", or, copy and add to. So if I provide a core class that contains all the necessary functions needed to make the app work, then me, or third party developers, can simply "drop in" a class that extends the core but is there to do a specific task. App owners can then simply choose which modules to activate on their app. I know this all sounds a bit vague at the moment but i think once i explain it in more detail you will understand.

OK, first I checked for php functions related to classes and I found one called get_declared_classes(). Now, lets say "drop in" modules are put into a folder that is read on application load (each module should be a class definition and so will appear in the list that get_declared_classes() returns), then those modules can be included everywhere in the app - the navigation menu, the admin panel etc. The problem with this method is that by default, the get_declared_classes() function will return over 100 already declared classes (on my server anyway) so a naming convention would have to be enforced for modules to work. hmmm.

Ah! I may have found a solution: php has a function called is_subclass_of which, as it suggests, checks if a declared class extends a specific one already declared. So if the app loads the classes in the module folder then checks for all classes that extend the core, they can be used in the app. The only problem now is name clashes - but after so much brain storming i think i will leave that problem until later

No comments: