Home > Programming, Wordpress > A Business Objects Framework for Wordpress

A Business Objects Framework for Wordpress

January 3rd, 2009

In this series of articles, I will cover the development of a business objects framework written in PHP for the Wordpress blogging platform.  I come from a Java/C++/C# background, so I am quite fond of the benefits of Object Oriented Programming when it comes to validating and persisting data to a database.  The framework  I  will construct draws inspiration from my work on other platforms.  Some of you who are experienced PHP programmers may think that my approach is strange.  Those of you with any experience with the CSLA framework may see a lot of similarities in the tutorial framework and older versions of CSLA.

Why Build a Framework?

Frameworks are useful for many reasons. Below is a short list of some of the most common benefits of developing a business objects framework.  For an exhaustive presentation on the rationale for using frameworks as well as a complete discussion of the design of a complete framework, I recommend Expert C# 2008 Business Objects.

  • Separation of Concerns – Code for the business logic and persistence details may exist in one or more layers.  This keeps database concerns and business logic out of the UI code.  A layered architecture makes it easier to build a variety of user interfaces for the same code base.
  • Specialization of Tasks -   The layered architecture allows people on a team to work on the programming tasks for which they are most suited.  I am a terrible web developer.  I like the fact that I can build a robust core and let the people with black turtlenecks put a slick user interface on top of it.  It is also a relief to designers that they can concentrate on the interface and use a simple, clean API which has been prepared for them by the core programmers.
  • Coding Standards – Frameworks set a good example by helping to establish coding style and methods for all of the developers on a team.  Even when working alone, the establishment of styles and patterns is very helpful and increases productivity.
  • Collaboration – All of the above items result in better collaboration in a team environment.  It is easy to get help from others when you have a clean and easy to follow code base.  New trainees also get up to speed a lot faster in the presence of a framework.  This builds confidence very early for new people and it also means that they are actually helping out on day one.
  • Code Generation – Established style and methodology make it easy to generate a significant percentage of your boring, boiler plate, error prone work using a code generation tool.  It is fairly easy to write code generation tools and there are a few really nice free tools to do the job as well.  We’ll get in to this in other articles.

What Will Our Framework Do?

The framework we are going to design will take care of the following tasks.

  • CRUD - Creation, Retrieval, Update and Deletion of records in the database.
  • Validation – Our objects will be self validating.  All validation rules for fields and business logic for the entities will be represented as classes.

Our framework will be implemented in one layer.  I am creating the framework for use with the Wordpress blogging system, so I’ll make use of some of the nice database features built in to Wordpress.  The framework may be used outside the Wordpress environment by including the proper files which allow use of $wpdb.  For more information of $wpdb, go here.  Of course, you could use another database.  It is also possible to separate the actual data access code into another suite of classes.  This takes a lot of extra work, but it does allow you to swap out your database technology without changing the rest of your code. This approach makes sense if you might switch database platforms.

Before we continue and actually build the framework, we should give it a name. I am tired of typing “the framework”.  For a working title, let’s call it Monkey Wrench. My wife, Jana, is rather fond of monkeys, so I’m sure she would approve.

Coming Up. Building Monkey Wrench

In the next article, we will begin building the Monkey Wrench framework.  See you next time!

Also Available in This Series

Did you like this? If so, please bookmark it,
tell a friend
about it, and subscribe to the blog RSS feed.

Programming, Wordpress , , ,

  1. No comments yet.
  1. No trackbacks yet.