Is Creating Classes For Divs and Spabs Taking oop too far?
I'm getting into the practice of using oop for all my development now but am just wondering if I'm going too far with it.
Basically I have a class called Html which is used as an abstract class and acts as a base for classes used to create basic html elements i.e. I then have a "form" class which extends the html class and is used to build forms etc.
However I have also created a "div" and a "span" class which both extend html. Is creating classes for these going a bit too over the top?
I'm thinking based on the fact that I use an autoload function to load in these classes there will be a lot of calls to the file system when these need to be included
You could use the PHP DOM class, perhaps, and both avoid reinventing the wheel and also be accessing built-in, compiled methods.
Personally, I'm not a big fan of writing PHP to write HTML, with the possible exception of forms and form-handlers -- and I don't in practice really do that much, either.
Have to agree with NogDog on the using PHP DOM class. Also i will second the "not writing PHP to write HTML".
What real advantage is there in doing what you are doing other than creating more work for yourself?
First time I've heard of PHP dom. Will take a look into it. Thanks. I see what you guys mean about not using classes for basic html.
I'm trying to get used to oop a bit more and practice makes perfect I think so I was just trying to apply classes to things that I use over and over again to make them easier but seeing as it takes about as much effort to write html with a method as it does to actually write html it does seem redundant ha.
Can you recommend any other things in a php/mysql based website where classes would be best applied? At the moment the most useful implementations seem to be for:-
1. Validating forms
2. Generating Forms
3. Image upload
4. SQL Queries
Not a direct answer, but I recommend spending some time with PHP Objects, Patterns, and Practice. You might also consider downloading and playing around with one of the object-oriented PHP frameworks. (I found CodeIgniter to be one of the easiest to learn.)
Thanks NogDog. Book purchased. I've previously used codeigniter in my last job briefly and you're right it does seem the easiest especially compared to what I am tasked with learning in my new job, Zend, which seems albeit more advanced yet far more (unnecessarily) complicated than others frameworks. Although I am seeing the benefits in form validation.
I prefer to create my own classes though when working on personal projects hence my interest in oop best practices
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)