Hi Guys,
I am in the process of writing an object oriented PHP website, and I am a little confused as to what the typical industry trend is with regards to how OO to go? What I mean is for example at the moment I am creating the CMS and I am on the categories page, I have created classes and functions etc to handle various generic things, and I have a class and functions for getting categories from the database, this function returns an array of categories, should I create another function to build the tables, divs or whatever and display this, or should I handle it from here in the old fashioned way, considering the function will only be used once? Personally I think the old fashioned way would be easier to modify in the future, for example adding more category depths. Or is it better to create functions for everything?
What do you guys think?
How OO Should I Go
Page 1 of 13 Replies - 818 Views - Last Post: 04 November 2010 - 05:02 PM
Replies To: How OO Should I Go
#2
Re: How OO Should I Go
Posted 04 November 2010 - 11:22 AM
Personally I always seem to end up using a MVC pattern, so that's pretty much 100% OOP, with something like Smarty for the output.
But in general, I would try not to go so far in using OOP that it overly complicates the process. Sure, it's good to abstract repetitive things, but if the PHP code that is generating your HTML looks like DOM manipulation in Javascript, your overdoing it.
But in general, I would try not to go so far in using OOP that it overly complicates the process. Sure, it's good to abstract repetitive things, but if the PHP code that is generating your HTML looks like DOM manipulation in Javascript, your overdoing it.
#3
Re: How OO Should I Go
Posted 04 November 2010 - 04:45 PM
I agree with Atli. You should write everything as if you will have to make changes to it six months after you've forgotten about it, because odds are that you will. Do something too clever and you will regret it. OOP can be used to make things easier to manage, and that's how you should use it.
#4
Re: How OO Should I Go
Posted 04 November 2010 - 05:02 PM
OOP is for just that- modeling Objects, their attributes, and their interactions. Your design should reflect this.
Functions should be modular and reusable. So what I would do is have the function accept the appropriate parameters so it can build a the appropriate HTML given the appropriate parameters. For example, if you wanted to build a table with a header row, I'd have an array columnNames param, as well as the array for the Objects you want to output. Then build that table to populate the data one element per cell, with each Object's data on the same row. In this way, you allow for modularity and easy expansion in case the database is expanded.
Quote
should I create another function to build the tables, divs or whatever and display this, or should I handle it from here in the old fashioned way, considering the function will only be used once?
Functions should be modular and reusable. So what I would do is have the function accept the appropriate parameters so it can build a the appropriate HTML given the appropriate parameters. For example, if you wanted to build a table with a header row, I'd have an array columnNames param, as well as the array for the Objects you want to output. Then build that table to populate the data one element per cell, with each Object's data on the same row. In this way, you allow for modularity and easy expansion in case the database is expanded.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote









|