Jump to content

Recommended Posts

*Sorry for the long question*

 

Hello,

 

I have written a class which is quite large. Every page on my website creates a new instance of this class and uses at least some of the functions in it. Most of the pages however do not use the same functions. There are many functions that are not used as frequently as others.

 

The homepage might use the function $myclass->IsLoggedIn() and $myclass->SqlQuery('...') while the logout page might only use $myclass->IsLoggedIn().

 

Is there some way to only load the functions that are needed for a particular page? I was thinking of something along these lines:

 

On homepage:

 

$myclass->getDatabaseFunctions()->SqlQuery('...');

 

getDatabaseFunctions() would then check if the database functions were included and if not it would include a file that contains the database functions. The getDatabaseFunctions() function would then return its self so ->SqlQuery would work. This way if on a page the getDatabaseFunctions() function was never called the code would never be included, therefore making the pageload faster.

 

I also thought of using classes that would store the individual functions, the issue with this is that many of the functions require eachother. e.g. the IsLoggedIn() function may call the SqlQuery() function. I can not use 'parent' to access the main class in this case from the sub function classes because there has been no 'extend'ing. If in the sub function classes I were to extend the main class is it just RELOADING all the functions of the main class again? This would be redundant and would go against the purpose of this optomization.

 

If none of the methods I described actually work (if they do can you describe how since I failed to accomplish them correctly), then can anyone provide another means?

 

Thank you  :D,

Noah

Link to comment
https://forums.phpfreaks.com/topic/257245-optomize-class/
Share on other sites

You optimize your class by not stuffing all of your code into just one class.  You're not gaining anything by doing that, and you're certainly not writing OO code, despite using a class/object.  Before you go any further with OOP, you should try to learn the basics of the methodology.  Start here: http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_1?s=books&ie=UTF8&qid=1329587873&sr=1-1

Link to comment
https://forums.phpfreaks.com/topic/257245-optomize-class/#findComment-1318627
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.