TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-03-2008, 03:18 PM   #1 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default Learning about OOP

I hope I don't get in trouble for posting so much the past couple days, I'm not trying to dilute the boards. This just happens to be the best php forum I've found, and I'm in school getting my BS in interactive media. I'm doing a lot of coding lately, and trying to learn as fast as I can. So, I figure if I start my senior project now, I've got a three year head start on everybody else, muahaha.

Anywho... Right now my site is pretty small and probably doesn't need OOP, however I like the organization structure and feel that it gives me, so I'm trying to utilize it right now, and build based on that structure.

What I'm wondering at the moment, is the best way to avoid code repetition. I currently have three classes for my administrative backend, 'blog', 'gallery' and 'support'. I have certain code, (a buildURL() function and a paginate() function for example) along with opening a database connection that is part of all three classes. I want to centralize this, so what might be better?

Option 1) Create a fourth class, 'database' which would do all the db queries and basic functions, so two classes are created per page, $database = new database(); $support = new support(); for example, where $support->functions() could call $database->functions().

Option 2) Create a parent class, 'admin' or whatever, and create child classes (class support extends admin)? I haven't tried this yet, so I'm not entirely sure how much more effective it is or what benefits I get from it.

Any and all insights appreciated.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-05-2008, 06:32 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

After playing around with this for a few days, I decided to go parent::child with my classes. It seems to be working well so far and allows me to include a central configuration layer in my parent class as well, which solves another problem I was having with my include structure.
PHP Code:
class OOPs {

      function 
__construct() {
           
pardon::me();
      }

I dunno why, but that's funny to me.
-m
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:11 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design