![]() |
The correct way to use multiple classes?
Is this even close to the "correct" way to do this?
main-class.php PHP Code:
PHP Code:
PHP Code:
PHP Code:
Should I just combine it all into one big file? |
Nay, you're looking now into design patterns, for this sort of occasion perhaps a Registry pattern would suffice
Note: Technically speaking you COULD but it's just bad practice. php Code:
Alternatively you could something like the following php Code:
Can't remember for the life of me what the pattern is called. |
Ok, thanks.
I think it will be easier for me to just include everything into one file and one class. It will be more annoying for my 'ocd' but oh well... Many thanks. |
Why are you putting display code that is only going to be used in one file in a class? Objects are for core logic and code you want to re-use over and over again. The word "display" in a class almost always means you are doing it incorrectly.
The way I try to look at it is pretending that classes and objects have no access to any sort of HTTP output (echo, print, ect). Enfernikus, your final way is probably the best method. Just pass the object by reference opposed to value so a new instance is not created. |
I was searching to know something about Pattern. and this thread help me alot.
|
| All times are GMT. The time now is 09:52 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0