We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I’ve finally decided that it’s past the time to move on to that newfangled "object oriented" stuff. For anyone else who also needs to be dragged kicking and screaming into anything new, I’ll leave a trail of broken bodies... er... sites that I’ve found useful in the odyssey.

    So to start with, I dug up this set of articles to get my mind twisted into new ways of looking at things.

    http://nefariousdesigns.co.uk/archive/2006/05/object-oriented-concepts/
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 25847
      • 62 Posts
      @sottwell

      Great article! Thanks for the link.
        • 31337
        • 258 Posts
        Bruce Eckel has written *the* best books in the industry on OO development and design. Although his book are focused on Java, C++, and Python, the concepts are still valid for any other language (even a faux-OO language like PHP). I strongly recommend "Thinking In Java" from Eckel if you’re interested in learning this stuff.

        BTW, he makes his books available as a free download, but given their size, I’d suggest previewing them online and then buying them.

        Link to Java OO book: http://www.mindview.net/Books/TIJ/
          • 7231
          • 4,205 Posts
          I am dragging my feet big time with OO...so this old dog will be very interested in the bones that get tossed while on your quest. Thanks grin
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            What’s ironic is that I studied C++ and Java 15 years ago, and even had a very successful online course for beginning C++, so I know all the buzzwords and how it all works. I’ve just never actually done it.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 5274
              • 177 Posts
              I’m struggling through the OOP learning curve too. So many procedural coding habits to break... Here’s another link focused on PHP only that starts the beginners dive into OOP code:

              http://www.osnews.com/story/6788/A_Beginners_Crash_Course_into_Object_Oriented_Programming/page1/
                • 3749
                • 24,544 Posts
                When I learned OOP, (what seems like ages ago), one of the most helpful techniques for me was to write each class object on a separate 3x5 note card and list its attributes and methods.

                e.g.:

                Class: Person

                Attributes (variables):
                Eye color
                Hair Color
                Height
                Weight

                Methods (functions):
                Run
                Walk
                Sit
                Stand
                Lose Weight
                Change Hair Color

                When you have the right classes, everything gets done that needs to be accomplished and each class knows as little as possible about what’s on the other cards.

                Fancy terms like inheritance, polymorphism, and encapsulation aside, the heart of OOP for me is the fact that objects take care of their own business as often as possible rather than being operated on.

                If you have an object that’s essentially a database table, you don’t add to it, sort it, or search it. Instead, you send it a bit of data and tell it to add it to itself. If you want it sorted, you tell it to sort itself. If you want the results of the sort printed, saved to disk, or emailed, you just sent the table object a message telling it to execute the appropriate method. If you want to search the table, you send it the search key and ask it to search itself.

                The power of this in terms of maintaining and extending your code is unbelievable. Now you can completely redo the sorting method used inside the object and know that it can’t possibly have any side effects. Any other object can, at will, call the methods of the table object. Best of all, if something doesn’t work, you usually know exactly where to look for the problem -- inside the class.

                As an aside: OOP has its dark side, too. Microsoft ruined word processing (IMHO), perhaps forever, when they created Word as an OOP word processor and chose the paragraph as the fundamental object. In WordPerfect (the Betamax of word processors), every formatting command changes the state of the text from that point onward. In Word, otoh, it changes either the current selection or the current paragraph. Each paragraph stores the complete information for that paragraph in a block at the end of the paragraph. (That’s why hitting backspace at the beginning of a paragraph will destroy the formatting of the previous paragraph.) Of course almost all of that information is redundant and it’s easy to have subtle changes from paragraph to paragraph that will drive a compositor completely mad. It’s totally the wrong design for a word processor but marketing and a powerful set of add-ons has made it work.

                Bob
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting