Classes and objects - please explain

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cyktor@hotmail.com

    Classes and objects - please explain

    Hey all,

    PHP is my first serious programming language (have some exp w/
    javascript), so this notion of classes and objects confuses me. What's
    a good way for me to understand this?

    -cyktor

  • whiskey

    #2
    Re: Classes and objects - please explain

    Technically speaking, in JavaScript you don't have classes, but only
    objects. Remember that it is a prototype based language.
    Anyway, JavaScript won't help you much with understanding classes and
    objects. Read some OOP books. But before you do, teach yourself some
    procedural programming. Because *some* ain't enough. And, in the end,
    most of the time you don't actually need OOP to go from A to B.

    Comment

    • Peter Fox

      #3
      Re: Classes and objects - please explain

      Following on from 's message. . .
      >Hey all,
      >
      >PHP is my first serious programming language (have some exp w/
      >javascript), so this notion of classes and objects confuses me. What's
      >a good way for me to understand this?
      >
      >-cyktor
      >
      Read a book?

      --
      PETER FOX Not the same since the e-commerce business came to a .
      peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
      2 Tees Close, Witham, Essex.
      Gravity beer in Essex <http://www.eminent.dem on.co.uk>

      Comment

      • cyktor@hotmail.com

        #4
        Re: Classes and objects - please explain

        By procedural programming, do you mean C? Please give me some
        suggestions for procedural languages to learn.

        -cyktor

        Comment

        • Harley

          #5
          Re: Classes and objects - please explain

          A great text for PHP in general and OOP in particular is "Beginning PHP 5
          and MySQL" by Jason Gilmore. A trip to the local bookstore or amazon.com
          would provide you with more information than a reply in this forum.

          Harley

          P.S. If you want to use OOP skip PHP-4 and go directly to PHP-5 which has
          much more functional OOP support.

          <cyktor@hotmail .comwrote in message
          news:1162480651 .174204.297150@ b28g2000cwb.goo glegroups.com.. .
          Hey all,
          >
          PHP is my first serious programming language (have some exp w/
          javascript), so this notion of classes and objects confuses me. What's
          a good way for me to understand this?
          >
          -cyktor
          >

          Comment

          • IchBin

            #6
            Re: Classes and objects - please explain

            cyktor@hotmail. com wrote:
            Hey all,
            >
            PHP is my first serious programming language (have some exp w/
            javascript), so this notion of classes and objects confuses me. What's
            a good way for me to understand this?
            >
            -cyktor
            >
            You can just look at the php manual:

            version 4


            version 5
            PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


            You can also just Google for OOP Tutorial

            OOP and OOD terminology are the same in any language. Some languages
            implement more of OOP\OOD than others.

            --
            Thanks in Advance... http://ichbin.9999mb.com
            IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
            _______________ _______________ _______________ _______________ __________
            'If there is one, Knowledge is the "Fountain of Youth"'
            -William E. Taylor, Regular Guy (1952-)

            Comment

            • Moot

              #7
              Re: Classes and objects - please explain

              cyktor@hotmail. com wrote:
              By procedural programming, do you mean C? Please give me some
              suggestions for procedural languages to learn.
              >
              -cyktor
              In most cases, an OOP language is also procedural. OOP is, at its
              core, a fancy way to write modular and reusable procedural code,
              because within all the layers of classes and functions, you still have
              individual lines of code saying:
              assign variable X
              if something, then something
              do this
              do that

              ^- that is procedural code.

              As for learning OOP, oh boy, where to begin? While it isn't strictly
              an OOP book, I highly recommend going and getting a copy of The
              Pragmatic Programmer and reading it cover to cover, and then once more
              just to make sure you didn't miss anything. It won't teach you the
              nuts and bolts of OOP, but it will lay a solid foundation of principles
              that will help you understand the *why* of OOP in addition to the *how*.

              Comment

              • David

                #8
                Re: Classes and objects - please explain

                A class is more specific name for the generic idea of an object.

                Basically, it allows you to put code and data into a container and
                tell the container to act on something and give me back a response. A
                real example is a remote control which accepts the pressing of the
                "power" key and then tells the TV to turn on/off.

                YOu do need to get a basic book on object design if you plan to use
                classes.

                On 2 Nov 2006 07:17:31 -0800, cyktor@hotmail. com wrote:
                >Hey all,
                >
                >PHP is my first serious programming language (have some exp w/
                >javascript), so this notion of classes and objects confuses me. What's
                >a good way for me to understand this?
                >
                >-cyktor

                Comment

                • David

                  #9
                  Re: Classes and objects - please explain

                  This is a basic OO tutorial



                  On 2 Nov 2006 07:17:31 -0800, cyktor@hotmail. com wrote:
                  >Hey all,
                  >
                  >PHP is my first serious programming language (have some exp w/
                  >javascript), so this notion of classes and objects confuses me. What's
                  >a good way for me to understand this?
                  >
                  >-cyktor

                  Comment

                  • lawrence k

                    #10
                    Re: Classes and objects - please explain


                    cyktor@hotmail. com wrote:
                    By procedural programming, do you mean C? Please give me some
                    suggestions for procedural languages to learn.
                    PHP without objects and classes is a good enough starting point to
                    learn procedural programming:

                    $howManyHats = 4;
                    $howManyHats = $howManyHats + 3;
                    setcookie("howM anyHats", $howManyHats);

                    Things happen one at a time, straight down the page. You can use
                    functions, which means the code goes into those code blocks, but it is
                    still pretty straightforward .

                    With objects, you'd suddenly have some variables that are maybe set
                    inside of objects, and therefore the code is no longer so
                    straightforward . If HatObject sets a variable called $yardsOfCloth in
                    its constructor (let's say a value of 34):

                    $hatObject = new HatObject();
                    $clothInYards = $hatObject->getYardsOfClot h();
                    echo $clothInYards; // shows 34

                    Comment

                    • lawrence k

                      #11
                      Re: Classes and objects - please explain


                      David wrote:
                      A class is more specific name for the generic idea of an object.
                      Possibly you meant the opposite of this? An object is one specific
                      instance of a class. A class is a template for making certain kinds of
                      objects, but each object made from that class is its own specific
                      variable.





                      >
                      Basically, it allows you to put code and data into a container and
                      tell the container to act on something and give me back a response. A
                      real example is a remote control which accepts the pressing of the
                      "power" key and then tells the TV to turn on/off.
                      >
                      YOu do need to get a basic book on object design if you plan to use
                      classes.
                      >
                      On 2 Nov 2006 07:17:31 -0800, cyktor@hotmail. com wrote:
                      >
                      Hey all,

                      PHP is my first serious programming language (have some exp w/
                      javascript), so this notion of classes and objects confuses me. What's
                      a good way for me to understand this?

                      -cyktor

                      Comment

                      • whiskey

                        #12
                        Re: Classes and objects - please explain

                        All this explanations, OOP at a glance, seem futile to me. OOP ain't
                        that simple. So a book is recommended. Not only about classes and
                        objects, but about interfaces, inheritance, polymorphism, and so on and
                        so forth. I'm working with classes and objects for 3 years now and I
                        still have problems with object oriented thinking.

                        And books, well... I can't think of a suggestion. My first language was
                        C++, and my first OOP steps were from "Jamsa's C/C++ Programmer's
                        Bible". The rest is history :-D

                        And, btw, cyk...@hotmail. com, learn a true programming language (not
                        JavaScript), such as C or C++, start with the beginning (procedural
                        programming) and then think of OOP. It's not something you learn in 24
                        hours.

                        Comment

                        • Pedro Graca

                          #13
                          OT: Programming language [was: Classes and objects - please explain]

                          whiskey wrote:
                          And, btw, cyk...@hotmail. com, learn a true programming language (not
                          JavaScript),
                          JavaScript /is/ a true programming language



                          --
                          I (almost) never check the dodgeit address.
                          If you *really* need to mail me, use the address in the Reply-To
                          header with a message in *plain* *text* *without* *attachments*.

                          Comment

                          • Rafe Culpin

                            #14
                            Re: Classes and objects - please explain

                            In article <1162544496.635 446.147260@m73g 2000cwd.googleg roups.com>,
                            alex.habar.nam@ gmail.com (whiskey) wrote:
                            All this explanations, OOP at a glance, seem futile to me. OOP ain't
                            that simple. So a book is recommended. Not only about classes and
                            objects, but about interfaces, inheritance, polymorphism, and so on and
                            so forth. I'm working with classes and objects for 3 years now and I
                            still have problems with object oriented thinking.
                            >
                            And books, well... I can't think of a suggestion. My first language was
                            C++, and my first OOP steps were from "Jamsa's C/C++ Programmer's
                            Bible". The rest is history :-D
                            PHP 5 Objects, Patterns, and Practice.
                            Matt Zandstra, Apress
                            ISBN 1-59059-380-4

                            But it assumes existing knowledge of PHP and of procedural programming.

                            Comment

                            • whiskey

                              #15
                              Re: Classes and objects - please explain

                              Pedro Graca wrote:
                              JavaScript /is/ a true programming language
                              Sure it is true, rather a true *scripting* language.
                              One friend o'mine once said: "Life's hard without pointers..." :-)

                              Rafe Culpin wrote:
                              But it assumes existing knowledge of PHP and of procedural programming.
                              Of course, that's what I'm trying to say. Learn to do it in a
                              procedural way, and then start to better organise your application as
                              whole by using an OO aproach.

                              Comment

                              Working...