SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few OOP Questions...

    Firstly, I need a way to quicken my coding--perhaps a framework?

    Next, I've read about modular scripts, I'm guessing modules are like plugins for mambo and such... am I right here? Also, how do I make something modular? I want this script I'm writing to be fully customizable--everything from the way news is displayed (meaning either: author credentials, news, edit buttons or; edit buttons, news, author credentials. These aren't just a set of preset options, they are completely admin-controlled.), all the way to allowing or disallowing user registrations.

    While doing all this, there shouldn't be much overhead (I'd like to keep the script as small as possible). I want 3rd-parties to have the ability to create templates, and implement them with nothing more than uploading it, logging in, and choosing 'Install Template'. No code changes. I want 3rd-parties to have the ability to create modules. e.g. a calander module, or a users-online module. Also should be able to create modules for the admin section, for complete customizability. Like, someone could create a calander module for the admin section, when you go in there, you can edit the way the calander is displayed. e.g., edit the .css file.

    Where can I start learning how to do all this?

    Thanks in advance,
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  2. #2
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    There are many low level OO books, but I'm not so familiar with those. One book you definitely want to tackle though is Refactoring, by Martin Fowler. Gets to the core skill of object coding like no other book.

    I wouldn't start with a framework though. You will overwhelm yourself. Write a few small apps and when you need a new feature, rework the code so that it can do it without any repetition. Once you do a few apps, the common heart iof teh framework. that's actually how real frameworks are written too.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Kansas City, MO
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would second Marcus' caution on frameworks. Never build code relying on someone else's code unless you could have written it all by yourself if you had to. If you can't, and you run into a bug you're up the creek.

    I haven't read Fowler's Refractoring (it's on my to read list), but I would also recommend Pragmatic Programmer and Object Oriented Thought Process. Neither deal with PHP, but both serve as excellent foundations for programming in any language.

    As for your question about modular scripts - it depends on who you ask. Each person has their own definition. Properly written OO code is modular by nature, but just because it's OO doesn't mean that it is. Likewise, just because code isn't OO doesn't mean that it's not modular.

  4. #4
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    What I want to know about the modular code, is I should be able to write a small script, drop it in a folder, the CMS (or whatever the app be), see's "Hey, theres a new file in there". So it checks it out, if it appears to be a plugin, it installs it, else it ignores it, assuming its just a required file for a plugin.

    This sounds nearly impossible to be functional... It would have to install it (how in the world would you do this!?), then it would have to put a little line, maybe something like $class->calendar(); in the correct spot... perhaps the 3rd party user wanted it in the right nav box. so it would find that, and then you would have a calendar to the right of the page.... This should also be customizable, meaning someone else downloads this guys plugin, and he wants it to the left... he should be able to login to the admin section and easily decide this...

    How I think it would have to be done is. Upon ever pageview of the plugins place in administration, it scans the plugins folder for something it doesn't know about yet. If it finds it, you have the choice to install it.

    Then, you would have 3 functions--1 for left nav, 1 for content, 1 for right nav--Then upon installation, it finds out where the writer of the plugin wanted it (in a variable that always has the same name). Then it adds $class->calendar() to the correct function. This function is called on the page, which is just a big list of other functions that want to be in the same place, and prints it out. Therefor creating an entire page out of... 3 functions, which call all the others.

    IMO, there has to be an easier way... am I right?

    Thanks,
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  5. #5
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm...

    Look at this configuration file for example, which I have for a root action handler,

    PHP Code:
    $config = array(
            
    'body'    =>    array(
            
                
                
    'handler'    =>    'home/',
                
    'classid'    =>    'HomePageBodyActionHandler',
                
    'configs'    =>    '',
                
    'statics'    =>    array(
                
                
                     
    'title'        =>    'Welcome to our Home Page',
                    
    'heading'    =>    'Welcome to our Home Page',
                    
    'description'    =>    'Welcome to our home page, where you can learn more about us...'
                
    ) ),
                
            
    'menu'    =>    array(
            
            
                
    'handler'    =>    'menu/',
                
    'classid'    =>    'MenuActionHandler',
                
    'configs'    =>    '',
                
    'statics'    =>    '' 
                

        ); 
    For example, if this was my home page, and this being the root configuration file for the root action handler, then the root has 2 children, ie Body and Menu.

    These are pluggable in their nature. I can plugin any action handler without going near any script. There is also the abstraction, that the base action handler doesn't actually expect any configuration file at all.

    It is entirely optional in that regards. For example, the Body action handler in it's self has no child action handlers. Why? Well, the array index 'configs' has no file specified, to which configuration that action handler (Body in this case) should use. If I wanted the Body to have child action handlers, I would have something like this in the configuration file, ie

    PHP Code:
    ...
    'body'    =>    array(
            
                
                
    'handler'    =>    'home/',
                
    'classid'    =>    'HomePageBodyActionHandler',
                
    'configs'    =>    'pathname/leading/to/config/config.php',
                
    'statics'    => ... 
    Then, that configuration file would be fetched, and the Body child action handlers would be created. On, the point of the earlier abstraction of the base action handler, a given action handler in it's self can modify it's child action handlers, and their configuration.

    Ie, if there is to be a configuration file passed or not, on the fly... Ultimately the configuration I am saying, does not actually need to come from a file, it could just as well come from the action handler it's self as well

    To me, that is what pluggable means, but other members have their own views on the subject, which at times, has been heavily debated in the past.

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If for example the following is the Root action handler, you could do this,

    PHP Code:
    // ... front controller
    // ...
    $root = new RootActionHandler(); // no configuration file passed
    $response -> render$root );
    // ... 
    PHP Code:
    // root
    public function executeIResponse $response$nodes ) {
    // and when IResponse reaches here,...
    $body = new HomePageBodyActionHandler();
    $menu = new MenuActionHandler();
    $this -> attach$body );
    $this -> attach$menu );
    // ... rest of script

    And Body and Menu are still processed as normal. If for example, the Body requires child action handlers, you can either do it via the configuration file**, or create the child action handlers themselves in the execute(...) of the Body action handler it's self

    **
    PHP Code:
    // ... root
    public function executeIResponse $response$nodes ) {
    $body = new HomePageBodyActionHandler'pathname/to/config/file/config.php' );
    // ... as before

    Hope that helps some way at least.

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Kansas City, MO
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jabird
    IMO, there has to be an easier way... am I right?
    There's always an easier way, and there's always a harder way...

    The best way to work out this type of a problem is write out a unit test (search the forums for "test driver design", I'm sure there's tons on here) that tests for the behavior you want, then start filling in the code. Once you have it functional, then you can start refractoring it to make it do its thing better.

    Just as a side note, what you're describing is several independent steps. Check out the web and/or books for information on use cases (I believe Pragmatic Programmers has a section on them) and write out a use case. Refine that a bit, and then you'll start to see the elements (or modules) of your code start leaping off the page at you.

  9. #9
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the past 2 posts with code included... that went WAY over my head, I've not used arrays anything like that before... the most advanced array I've made was for a BBCode Parser, and that was pretty small... Think you could explain that a little more elaborately?

    Thanks,
    ~Jabird
    Jabird.com
    If I were binary... I'd be all 1's for you.
    BBCode trouble?

  10. #10
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As this is about getting into patterns I think you should read some book about it first.

  11. #11
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jabird
    For the past 2 posts with code included... that went WAY over my head, I've not used arrays anything like that before... the most advanced array I've made was for a BBCode Parser, and that was pretty small... Think you could explain that a little more elaborately?
    There is a quote often attributed to Louis Armstrong that when asked "What is Jazz?" he answered "If you have to ask, you ain't never gonna know!"

    Not that you shouldn't ask questions, but you probably should make an effort read as much as you can and get experience by experimenting with different ways to design and code.
    Christopher

  12. #12
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you are at this stage
    print_r($object); and
    print_r($array);
    are your friends. Stick with it.

  13. #13
    SitePoint Guru
    Join Date
    May 2005
    Location
    Finland
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function debug() {
       echo 
    '<pre>';
       foreach(
    func_get_args() as $arg) {
          
    print_r($arg);
       }
       echo 
    '</pre>';


  14. #14
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even better:

    PHP Code:
    function debug() {
       echo 
    '<pre>';
       foreach(
    func_get_args() as $arg) {
          print 
    htmlentities(print_r($argtrue));
       }
       echo 
    '</pre>';



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •