WordPress Themes vs Plugins and the single responsibility principle

Have you every thought about what should go into a WordPress theme and what should go into a WordPress plugin? This is a question that I for sometime have been thinking reading about.

The WordPress codex has the following definitions:

”Fundamentally, the WordPress Theme system is a way to ”skin” your weblog. Yet, it is more than just a ”skin.” Skinning your site implies that only the design is changed. WordPress Themes can provide much more control over the look and presentation of the material on your website.” — http://codex.wordpress.org/Theme

”Plugins are tools to extend the functionality of WordPress. …. Plugins offer custom functions and features so that each user can tailor their site to their specific needs.” — http://codex.wordpress.org/Plugins

Based on these definitions, we can say that a theme is a about adding a look and feel / design / skin to the site and it can also extend functionality, while a plugin is only about extending functionality.

We could say the theme concept in some way embrace the plugin concept.

For as long as you never need to share functionality between several themes you could include the functionality in the theme it self and there is no need to create a plugin.

As soon as you need to share the functionality between two themes then you would need to create a separate plugin for that functionality.

But, creating a plugin is simple. Separating the design of the site and the functionality of the site is enforcing the single responsibility principle (SRP) pattern to your code base. The theme would be responsible for the design and the plugin would be responsible for the functionality.

It is more future proof to separate these concerns then not separating them since you most probably will create undesired dependencies and assumptions in the code base between the concerns if you don’t separate the the concerns. This would make it hard to separate them in the future.

What do you think? Is a good idea to separate the design and functionality into a theme and plugin respectively even if it is currently not needed? Leave a comment and let us know!

This entry was posted in Web Development and tagged , , , , . Bookmark the permalink.