Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build an Object-oriented File System in PHP

Using a simple file storage convention and some PHP code, you can create a hierarchical file system that mimics many object-oriented concepts, facilitates reuse, and simplifies your Web development efforts.


advertisement


he term "object-oriented" is vague and frequently misunderstood. Jonathan Rees (with more insight than the average programmer) attempted to define its meaning , but even his definition does not necessarily encompass the topic completely. Despite the difficulties of pinning down the terminology, for the purposes of this article, you can assume an "object-oriented file system" has a specific meaning—it is a way to take advantage of traditional object-oriented concepts such as inheritance, by organizing your files and directories as if they were a class hierarchy. This may seem like an odd idea, but in practice, it's extremely useful. Adopting an object-oriented file system provides the following benefits:

  • Context Sensitivity: Perhaps the most important benefit of an object-oriented file system is that files can automatically configure themselves based on context. The class hierarchy serves primarily as an easy way to define context for your site. Then the various page elements can be selected automatically based on that context.
  • Reduced Duplication: The idea is that changes should be made once, and only once. A single piece of information should not be stored in more than one place, nor should a concept be implemented repeatedly. For example, you can easily change the appearance of an entire site, or any subsection of it, by making a single change. Instead of writing the same things over and over, you need to tell the system only how this page differs from other pages. Any commonalities are handled automatically.
  • Ease of Specialization: While it is easy to do things automatically from context, the system also makes it easy to give pages unique behavior. You can override the context without difficulty, to make pages or sections stand out from the rest of the site.
  • Easy Maintenance: Moving files and directories around is easy when you don't have to worry about breaking links. Just make sure that you move your file or directory into a directory with a compatible interface, and the system will sort out the details automatically. By interface, I mean the parent classes or folders must implement the features your migrant page needs—images, files, functions, templates, or other objects which make up a complete page. But if these things are not available, it's still fairly simple to import components from brother or sister classes. This allows you to use both vertical and horizontal inheritance.
  • Clean, Clear URLs: Readers and search engines both like to use your Web address to guess what your content will be. URLs which describe their content in human-friendly terms will be easier to find, easier to remember, easier to share and link to, and get higher search engine placement. Organizing your content into a class hierarchy has the side effect of producing human-friendly and spider-friendly URLs.
An object-oriented file system might be better labeled as a contextual framework. Though it provides very helpful features, you will still need to apply basic organization skills to make it work well. The framework is both a mechanism to provide basic object-oriented features and an approach or policy for organizing content. By using both the mechanism and the policy, you can create and maintain sites with relatively little effort.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date