I have a couple new projects in the hopper right now, both using my usual PHP/MySQL platform. In an effort to better myself as a developer, and get reacquainted with a concept I haven't used for a while, I decided to intentionally make these projects object oriented.
PHP is, by nature, a procedural scripting language, but it has for the last while, had many OO features and functions introduced into it. I have only used OO in Java coding, and that is pretty limited experience for me, so I figured I'll give it a go.
Thus far, after a few days working with it, I find it interesting, but, like anything it has it's pro's and con's. It is kind of nice keeping each object individualized in it's own object instantiation. If you want to change the properties of any given object, you simply change the class or the properties of it, more accurately.
The interesting thing I have learned though is that it's actually very expensive in terms of performance, to use an OO design. It does cut down development time because objects are centralized, but the cost of that gain is in performance. So, that leads me to wonder, which is better, is better performance for the visitor more desirable, or more difficult development for the developer. I guess the answer to that depends on two things; How selfish the developer is and how big of a performance hit your site takes
If you have a relatively small project with a couple objects the performance probably won't be affected that much, but then, development probably wouldn't be that incredibly difficult either. On the flip side, a bigger project would take a bigger performance hit due to more objects, and probably larger objects, which would affect your visitors experience more, and, being a larger project the OO architecture would stand to help you more in terms of developing in a larger scale environment.
I will admit, I very much like the impact it has on the look of my code. It's nice having all the logic behind the scenes in the object class includes. it makes the procedural PHP files much smaller and more easily readable at a quick look to find bugs or make quick layout changes. After a couple weeks of playing around in my latest project I am getting more comfortable and starting to notice development speed improvements. Once the object class is created, using it from different areas of the web site is very quick and easy. The PHP files themselves are pretty much just a presentation layer and simply object instantiations and property definitions.
All in all, I will be using mostly OO going forward for a while, see how it goes. Though I can see a little bit of performance decrease, it's not horrible, and it does make the architecture of the sites much more logical and easy to work within.
Monday, December 17, 2007
Object Oriented PHP
Posted by
dB Masters
at
7:34 AM
Labels: PHP, Web Development
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment