www.webdeveloper.com
Results 1 to 6 of 6

Thread: Is Creating Classes For Divs and Spabs Taking oop too far?

  1. #1
    Join Date
    Dec 2010
    Posts
    232

    Is Creating Classes For Divs and Spabs Taking oop too far?

    *spans

    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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2012
    Posts
    59
    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?

    Kind regards,
    Scott

  4. #4
    Join Date
    Dec 2010
    Posts
    232
    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

    Any others?

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    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.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Dec 2010
    Posts
    232
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles