This is a discussion on Best way to integrate classes within the PHP Language forums, part of the PHP Programming Forums category; Nikolai Chuvakhin wrote: > "Swartz" <swartz@inbox.ru> wrote in message > news:<104khdbgrafe251@corp....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Nikolai Chuvakhin wrote:
> "Swartz" <swartz@inbox.ru> wrote in message > news:<104khdbgrafe251@corp.supernews.com>... > >>I'm working here on a small project of mine. I'm not new to programming, but >>I'm new to PHP. You have to understand that I'm coming from C++, OOP world, >>so my code might seems a little too "object"-ified. > > Actually, it doesn't seem "a little too objectified"; it seems > unnecessarily objectified. You are creating lots of overhead > here... > >>What is the best approach to integrate the two classes? > > The best approach is not to have classes at all, unless you > need them. > >>How would you do it? > > By writing standalone functions: login(), logout(), etc. Ask > yourself a simple question: will you ever have more than one > instance of your Session class running? Most likely, the answer > to that question is no, so you will do just fine with standalone > functions; they will get the job done and won't create any > unnecessary overhead... All your rant against OO could be justified if PHP had any other support for modularity. Since this is not the case, and there's no way to have functions or vars existing on a 'module' scope only, the only way to write clean PHP code is to use OO. The "unnecessary overhead" is the price to pay to have clean, modular code with lo coupling, and as such is *never* "unnecessary" except perhaps for the most basic, throw-away scripts. Bruno |
|
|||
|
"Bruno Desthuilliers" <bdesth.quelquechose@free.quelquepart.fr> wrote in message news:404ba4bc$0$305$636a15ce@news.free.fr... > Nikolai Chuvakhin wrote: > > "Swartz" <swartz@inbox.ru> wrote in message > > news:<104khdbgrafe251@corp.supernews.com>... > > > >>I'm working here on a small project of mine. I'm not new to programming, but > >>I'm new to PHP. You have to understand that I'm coming from C++, OOP world, > >>so my code might seems a little too "object"-ified. > > > > Actually, it doesn't seem "a little too objectified"; it seems > > unnecessarily objectified. You are creating lots of overhead > > here... > > > >>What is the best approach to integrate the two classes? > > > > The best approach is not to have classes at all, unless you > > need them. > > > >>How would you do it? > > > > By writing standalone functions: login(), logout(), etc. Ask > > yourself a simple question: will you ever have more than one > > instance of your Session class running? Most likely, the answer > > to that question is no, so you will do just fine with standalone > > functions; they will get the job done and won't create any > > unnecessary overhead... > > All your rant against OO could be justified if PHP had any other support > for modularity. Since this is not the case, and there's no way to have > functions or vars existing on a 'module' scope only, the only way to > write clean PHP code is to use OO. What is your definition of 'clean' code. It is possible to write beautiful code without using OO, just as it is possible to write crap code with OO. Using one technique or the other does not guarantee that your code will be either excellent or excrement - it is not the technique, it is the technician. -- Tony Marston http://www.tonymarston.net |