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
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-22-2010, 10:03 AM   #1 (permalink)
The Wanderer
 
andformore's Avatar
 
Join Date: Dec 2009
Posts: 17
Thanks: 2
andformore is on a distinguished road
Default Confused About Objects...

So, I program in a procedural way for the most part, but have some experience with objects in PHP, Java, and a little C++. For my current project, Im considering making a switch to objects but I'm confused about whether or not this will be beneficial from a performance point of view.

My project deals with online flash cards, and its built in code igniter. The way its set up right now is that I use a function for each thing i need to access, and they are pretty unrelated. So, if I just need to display the title and description of a deck, I might call a function like:

PHP Code:
 $deckInfo getDeckInfo($deckId); 
Then, if I'm displaying the deck info along with that deck's tags, votes, comments, individual cards, and some other things, I'll simply call a function for each thing, set the results to an array, and then loop through the array and display those things.

I'm thinking my code would be nicer if I just made a deck object to handle all this, but I'm worried that an Object Oriented approach will use more resources than necessary.

For instance, If I had my deck object, it would take a deckId as a parameter and in the constructor it would get the basic deck info (title, description, dateEdited, etc). Then if I wanted the comments I would call $deckInstance->getComments();

What I'm worried about is that in many cases, like when I update the comments with ajax, I will only need the comments and not the basic deck info. It seems like I'm completely wasting a query in the constructor to get the basic info if i'm only going to use the comments. Is this worth worrying about? Should I not have the constructor get any data, and reserve the basic info for its own method? This seems strange though, for a deck object to exist, and not even store its title or the id of the user who created it.

Also, I have considered getting all the data in the constructor, so that I could access it all easily after making an instance of the object, but I feel like this would be a major waste of resources.

If I go the route where the constructor does not go to the database at all, then I feel like I'm not benefiting much from the Object Approach, I'm just grouping together a series of procedural functions.

Sorry this is so long, but I never know when or how to best use objects. Any thoughts?
__________________
Something interesting... If you visit one of my sites today, you'll probably double my unique visitors for the day! Shameless Plugs:
My Blog My Octopus Game My Flash Card Website
andformore is offline  
Reply With Quote
 



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

Similar Threads
Thread Thread Starter Forum Replies Last Post
onfocus and onblur events -- I'm confused, of course... Dave Absolute Beginners 2 10-20-2009 12:54 AM
Destroying related objects doubt sohdubom Advanced PHP Programming 1 08-10-2009 08:03 PM
Treat PHP Strings as Objects (Like Javascript) Wildhoney Tips & Tricks 14 06-19-2009 01:34 PM
I am.. confused Sirupsen General 8 06-15-2009 07:31 AM
All the Objects? Aaron Javascript, AJAX, E4X 1 02-17-2008 06:02 AM


All times are GMT. The time now is 01:46 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