OOP php user system

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yorian

    OOP php user system

    Hey,

    Although I've been using classes and object for quite a while now I've
    never actually programmed proper OO code yet. It ofcourse depends on
    what you call proper OO code. I have been seperating parts of the
    website. Like a user class, guestbook class, etc. But I've been
    putting all the code in one single class instead of of spreiding it.

    Since a short while I've been reading up on OOP and now I am trying to
    actually do things the way they should be done to make a nice
    maintainable module. Which in fact means that I'm trying to stick to
    some rules: Don't repeat yourself, seperation of concerns,
    encapsulation, etc.

    I've created (not finished just started it) a user system, this
    according to the mvc pattern. The names for the classes aren't perfect
    (user should actually be named userController, and userData should be
    named user, etc.).

    Could any of you guys have a look and see if I'm going in the right
    direction?

    The few classes (put in a single file for the sake of easy reading)
    can be found here: http://web-develop.nl/user_oop.phps

    Hope you guys can give me some useful comments.

    Thanks
  • Jessica Griego

    #2
    Re: OOP php user system


    "Yorian" <yorianbenjamin @hotmail.comwro te in message
    news:8b1c4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
    Hey,
    >
    Although I've been using classes and object for quite a while now I've
    never actually programmed proper OO code yet. It ofcourse depends on
    what you call proper OO code. I have been seperating parts of the
    website. Like a user class, guestbook class, etc. But I've been
    putting all the code in one single class instead of of spreiding it.
    >
    Since a short while I've been reading up on OOP and now I am trying to
    actually do things the way they should be done to make a nice
    maintainable module. Which in fact means that I'm trying to stick to
    some rules: Don't repeat yourself, seperation of concerns,
    encapsulation, etc.
    >
    I've created (not finished just started it) a user system, this
    according to the mvc pattern. The names for the classes aren't perfect
    (user should actually be named userController, and userData should be
    named user, etc.).
    >
    Could any of you guys have a look and see if I'm going in the right
    direction?
    >
    The few classes (put in a single file for the sake of easy reading)
    can be found here: http://web-develop.nl/user_oop.phps
    >
    Hope you guys can give me some useful comments.
    The thing I like most, Yorian, is that it is well formatted! I don't know
    what language the comments are in, however I do recognize 'singleton'. For
    the classes that are singletons, you need to make the __constructor a
    private function and use the 'static' keyword for the other
    functions/variables in the class. You'd necissarily need a way to supply
    those singletons the constructor args. You can either let the caller set the
    values via 'setters' and/or create a static function, like 'initialize',
    that essentially carries out the responsibility of __construct. You should
    also think about defining __clone, __copy, etc. specifically as private so
    that you are guaranteed not to have more than one instance of the singleton.

    Again, I like the code most because I can readily tell what it is
    doing...because it is well formatted. Above all, that will save time, money,
    and frustration when you need to add to it or modify it in some way in the
    future.

    Cheers


    Comment

    • 703designs

      #3
      Re: OOP php user system

      On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
      "Yorian" <yorianbenja... @hotmail.comwro te in message
      >
      news:8b1c4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
      >
      >
      >
      Hey,
      >
      Although I've been using classes and object for quite a while now I've
      never actually programmed proper OO code yet. It ofcourse depends on
      what you call proper OO code. I have been seperating parts of the
      website. Like a user class, guestbook class, etc. But I've been
      putting all the code in one single class instead of of spreiding it.
      >
      Since a short while I've been reading up on OOP and now I am trying to
      actually do things the way they should be done to make a nice
      maintainable module. Which in fact means that I'm trying to stick to
      some rules: Don't repeat yourself, seperation of concerns,
      encapsulation, etc.
      >
      I've created (not finished just started it) a user system, this
      according to the mvc pattern. The names for the classes aren't perfect
      (user should actually be named userController, and userData should be
      named user, etc.).
      >
      Could any of you guys have a look and see if I'm going in the right
      direction?
      >
      The few classes (put in a single file for the sake of easy reading)
      can be found here:http://web-develop.nl/user_oop.phps
      >
      Hope you guys can give me some useful comments.
      >
      The thing I like most, Yorian, is that it is well formatted! I don't know
      what language the comments are in, however I do recognize 'singleton'. For
      the classes that are singletons, you need to make the __constructor a
      private function and use the 'static' keyword for the other
      functions/variables in the class. You'd necissarily need a way to supply
      those singletons the constructor args. You can either let the caller set the
      values via 'setters' and/or create a static function, like 'initialize',
      that essentially carries out the responsibility of __construct. You should
      also think about defining __clone, __copy, etc. specifically as private so
      that you are guaranteed not to have more than one instance of the singleton.
      >
      Again, I like the code most because I can readily tell what it is
      doing...because it is well formatted. Above all, that will save time, money,
      and frustration when you need to add to it or modify it in some way in the
      future.
      >
      Cheers
      Instead of using all of those getAttribute methods, you could use a
      generic __get method that returns the attribute.

      Thomas

      Comment

      • 703designs

        #4
        Re: OOP php user system

        On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
        On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
        >
        >
        >
        "Yorian" <yorianbenja... @hotmail.comwro te in message
        >
        news:8b1c4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com....
        >
        Hey,
        >
        Although I've been using classes and object for quite a while now I've
        never actually programmed proper OO code yet. It ofcourse depends on
        what you call proper OO code. I have been seperating parts of the
        website. Like a user class, guestbook class, etc. But I've been
        putting all the code in one single class instead of of spreiding it.
        >
        Since a short while I've been reading up on OOP and now I am trying to
        actually do things the way they should be done to make a nice
        maintainable module. Which in fact means that I'm trying to stick to
        some rules: Don't repeat yourself, seperation of concerns,
        encapsulation, etc.
        >
        I've created (not finished just started it) a user system, this
        according to the mvc pattern. The names for the classes aren't perfect
        (user should actually be named userController, and userData should be
        named user, etc.).
        >
        Could any of you guys have a look and see if I'm going in the right
        direction?
        >
        The few classes (put in a single file for the sake of easy reading)
        can be found here:http://web-develop.nl/user_oop.phps
        >
        Hope you guys can give me some useful comments.
        >
        The thing I like most, Yorian, is that it is well formatted! I don't know
        what language the comments are in, however I do recognize 'singleton'. For
        the classes that are singletons, you need to make the __constructor a
        private function and use the 'static' keyword for the other
        functions/variables in the class. You'd necissarily need a way to supply
        those singletons the constructor args. You can either let the caller set the
        values via 'setters' and/or create a static function, like 'initialize',
        that essentially carries out the responsibility of __construct. You should
        also think about defining __clone, __copy, etc. specifically as privateso
        that you are guaranteed not to have more than one instance of the singleton.
        >
        Again, I like the code most because I can readily tell what it is
        doing...because it is well formatted. Above all, that will save time, money,
        and frustration when you need to add to it or modify it in some way in the
        future.
        >
        Cheers
        >
        Instead of using all of those getAttribute methods, you could use a
        generic __get method that returns the attribute.
        >
        Thomas
        Ah, my fault, it's late. I meant that you can use __get to point to
        those methods automatically using call_user_func. So that
        $userInstance->last_name would call that method.

        Thomas

        Comment

        • Jessica Griego

          #5
          Re: OOP php user system


          "703designs " <thomasmallen@g mail.comwrote in message
          news:87a79792-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
          On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
          On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
          >
          >
          >
          "Yorian" <yorianbenja... @hotmail.comwro te in message
          >
          news:8b1c4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
          >
          Hey,
          >
          Although I've been using classes and object for quite a while now I've
          never actually programmed proper OO code yet. It ofcourse depends on
          what you call proper OO code. I have been seperating parts of the
          website. Like a user class, guestbook class, etc. But I've been
          putting all the code in one single class instead of of spreiding it.
          >
          Since a short while I've been reading up on OOP and now I am trying to
          actually do things the way they should be done to make a nice
          maintainable module. Which in fact means that I'm trying to stick to
          some rules: Don't repeat yourself, seperation of concerns,
          encapsulation, etc.
          >
          I've created (not finished just started it) a user system, this
          according to the mvc pattern. The names for the classes aren't perfect
          (user should actually be named userController, and userData should be
          named user, etc.).
          >
          Could any of you guys have a look and see if I'm going in the right
          direction?
          >
          The few classes (put in a single file for the sake of easy reading)
          can be found here:http://web-develop.nl/user_oop.phps
          >
          Hope you guys can give me some useful comments.
          >
          The thing I like most, Yorian, is that it is well formatted! I don't
          know
          what language the comments are in, however I do recognize 'singleton'.
          For
          the classes that are singletons, you need to make the __constructor a
          private function and use the 'static' keyword for the other
          functions/variables in the class. You'd necissarily need a way to supply
          those singletons the constructor args. You can either let the caller set
          the
          values via 'setters' and/or create a static function, like 'initialize',
          that essentially carries out the responsibility of __construct. You
          should
          also think about defining __clone, __copy, etc. specifically as private
          so
          that you are guaranteed not to have more than one instance of the
          singleton.
          >
          Again, I like the code most because I can readily tell what it is
          doing...because it is well formatted. Above all, that will save time,
          money,
          and frustration when you need to add to it or modify it in some way in
          the
          future.
          >
          Cheers
          >
          Instead of using all of those getAttribute methods, you could use a
          generic __get method that returns the attribute.
          >
          Thomas
          Ah, my fault, it's late. I meant that you can use __get to point to
          those methods automatically using call_user_func. So that
          $userInstance->last_name would call that method.

          ========

          IMO, that's very bad advice. __get and __set only get executed when a caller
          tries to access an *undefined* interface. You're abusing the actual intent
          of __get/set. It makes it terribly hard to debug and manage. It doesn't
          allow you to strongly type the input(s) or output(s). It's also a
          performance hit. Further, you should notice tools like php documentor and
          any screen dump of the object would not accurately show any validation for
          the properties being set. I'd think about always being specific and not try
          to rig the jury to obtain the get/set functionality that is supplied by
          other oop languages. __get and __set are NOT php's version of other
          languages' get/set construct.


          Comment

          • 703designs

            #6
            Re: OOP php user system

            On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
            "703designs " <thomasmal...@g mail.comwrote in message
            >
            news:87a79792-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
            On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
            >
            >
            >
            On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
            >
            "Yorian" <yorianbenja... @hotmail.comwro te in message
            >
            >news:8b1c486 4-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com....
            >
            Hey,
            >
            Although I've been using classes and object for quite a while now I've
            never actually programmed proper OO code yet. It ofcourse depends on
            what you call proper OO code. I have been seperating parts of the
            website. Like a user class, guestbook class, etc. But I've been
            putting all the code in one single class instead of of spreiding it..
            >
            Since a short while I've been reading up on OOP and now I am tryingto
            actually do things the way they should be done to make a nice
            maintainable module. Which in fact means that I'm trying to stick to
            some rules: Don't repeat yourself, seperation of concerns,
            encapsulation, etc.
            >
            I've created (not finished just started it) a user system, this
            according to the mvc pattern. The names for the classes aren't perfect
            (user should actually be named userController, and userData should be
            named user, etc.).
            >
            Could any of you guys have a look and see if I'm going in the right
            direction?
            >
            The few classes (put in a single file for the sake of easy reading)
            can be found here:http://web-develop.nl/user_oop.phps
            >
            Hope you guys can give me some useful comments.
            >
            The thing I like most, Yorian, is that it is well formatted! I don't
            know
            what language the comments are in, however I do recognize 'singleton'..
            For
            the classes that are singletons, you need to make the __constructor a
            private function and use the 'static' keyword for the other
            functions/variables in the class. You'd necissarily need a way to supply
            those singletons the constructor args. You can either let the caller set
            the
            values via 'setters' and/or create a static function, like 'initialize',
            that essentially carries out the responsibility of __construct. You
            should
            also think about defining __clone, __copy, etc. specifically as private
            so
            that you are guaranteed not to have more than one instance of the
            singleton.
            >
            Again, I like the code most because I can readily tell what it is
            doing...because it is well formatted. Above all, that will save time,
            money,
            and frustration when you need to add to it or modify it in some way in
            the
            future.
            >
            Cheers
            >
            Instead of using all of those getAttribute methods, you could use a
            generic __get method that returns the attribute.
            >
            Thomas
            >
            Ah, my fault, it's late. I meant that you can use __get to point to
            those methods automatically using call_user_func. So that
            $userInstance->last_name would call that method.
            >
            ========
            >
            IMO, that's very bad advice. __get and __set only get executed when a caller
            tries to access an *undefined* interface. You're abusing the actual intent
            of __get/set. It makes it terribly hard to debug and manage. It doesn't
            allow you to strongly type the input(s) or output(s). It's also a
            performance hit. Further, you should notice tools like php documentor and
            any screen dump of the object would not accurately show any validation for
            the properties being set. I'd think about always being specific and not try
            to rig the jury to obtain the get/set functionality that is supplied by
            other oop languages. __get and __set are NOT php's version of other
            languages' get/set construct.
            Sorry, Python's my first language and this sort of thing works very
            cleanly there. I'll keep these drawbacks in mind: I guess that __get's
            not quite ready for primetime.

            Thomas

            Comment

            • Jessica Griego

              #7
              Re: OOP php user system


              "703designs " <thomasmallen@g mail.comwrote in message
              news:b0914478-f249-4d4a-9e10-586c7092ac07@i2 0g2000prf.googl egroups.com...
              On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
              "703designs " <thomasmal...@g mail.comwrote in message
              >
              news:87a79792-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
              On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
              >
              >
              >
              On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
              >
              "Yorian" <yorianbenja... @hotmail.comwro te in message
              >
              >news:8b1c486 4-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
              >
              Hey,
              >
              Although I've been using classes and object for quite a while now
              I've
              never actually programmed proper OO code yet. It ofcourse depends on
              what you call proper OO code. I have been seperating parts of the
              website. Like a user class, guestbook class, etc. But I've been
              putting all the code in one single class instead of of spreiding it.
              >
              Since a short while I've been reading up on OOP and now I am trying
              to
              actually do things the way they should be done to make a nice
              maintainable module. Which in fact means that I'm trying to stick to
              some rules: Don't repeat yourself, seperation of concerns,
              encapsulation, etc.
              >
              I've created (not finished just started it) a user system, this
              according to the mvc pattern. The names for the classes aren't
              perfect
              (user should actually be named userController, and userData should
              be
              named user, etc.).
              >
              Could any of you guys have a look and see if I'm going in the right
              direction?
              >
              The few classes (put in a single file for the sake of easy reading)
              can be found here:http://web-develop.nl/user_oop.phps
              >
              Hope you guys can give me some useful comments.
              >
              The thing I like most, Yorian, is that it is well formatted! I don't
              know
              what language the comments are in, however I do recognize 'singleton'.
              For
              the classes that are singletons, you need to make the __constructor a
              private function and use the 'static' keyword for the other
              functions/variables in the class. You'd necissarily need a way to
              supply
              those singletons the constructor args. You can either let the caller
              set
              the
              values via 'setters' and/or create a static function, like
              'initialize',
              that essentially carries out the responsibility of __construct. You
              should
              also think about defining __clone, __copy, etc. specifically as
              private
              so
              that you are guaranteed not to have more than one instance of the
              singleton.
              >
              Again, I like the code most because I can readily tell what it is
              doing...because it is well formatted. Above all, that will save time,
              money,
              and frustration when you need to add to it or modify it in some way in
              the
              future.
              >
              Cheers
              >
              Instead of using all of those getAttribute methods, you could use a
              generic __get method that returns the attribute.
              >
              Thomas
              >
              Ah, my fault, it's late. I meant that you can use __get to point to
              those methods automatically using call_user_func. So that
              $userInstance->last_name would call that method.
              >
              ========
              >
              IMO, that's very bad advice. __get and __set only get executed when a
              caller
              tries to access an *undefined* interface. You're abusing the actual intent
              of __get/set. It makes it terribly hard to debug and manage. It doesn't
              allow you to strongly type the input(s) or output(s). It's also a
              performance hit. Further, you should notice tools like php documentor and
              any screen dump of the object would not accurately show any validation for
              the properties being set. I'd think about always being specific and not
              try
              to rig the jury to obtain the get/set functionality that is supplied by
              other oop languages. __get and __set are NOT php's version of other
              languages' get/set construct.
              Sorry, Python's my first language and this sort of thing works very
              cleanly there. I'll keep these drawbacks in mind: I guess that __get's
              not quite ready for primetime.

              ===========

              I understand, however Python's get/set is not php's get/set. I was *very*
              excited when I saw the __get/set in php for the first time! That is, until I
              saw that it was NOT what I was used to either. Maybe they'll put actual
              get/set constructs in another version down the road...because I have
              relatively no use for what php is trying to get out of the current
              implementation.

              Have a good one.


              Comment

              • Jerry Stuckle

                #8
                Re: OOP php user system

                703designs wrote:
                On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                >"703designs " <thomasmal...@g mail.comwrote in message
                >>
                >news:87a7979 2-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                >On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                >>
                >>
                >>
                >>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                >>>"Yorian" <yorianbenja... @hotmail.comwro te in message
                >>>news:8b1c486 4-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                >>>>Hey,
                >>>>Although I've been using classes and object for quite a while now I've
                >>>>never actually programmed proper OO code yet. It ofcourse depends on
                >>>>what you call proper OO code. I have been seperating parts of the
                >>>>website. Like a user class, guestbook class, etc. But I've been
                >>>>putting all the code in one single class instead of of spreiding it.
                >>>>Since a short while I've been reading up on OOP and now I am trying to
                >>>>actually do things the way they should be done to make a nice
                >>>>maintainabl e module. Which in fact means that I'm trying to stick to
                >>>>some rules: Don't repeat yourself, seperation of concerns,
                >>>>encapsulati on, etc.
                >>>>I've created (not finished just started it) a user system, this
                >>>>according to the mvc pattern. The names for the classes aren't perfect
                >>>>(user should actually be named userController, and userData should be
                >>>>named user, etc.).
                >>>>Could any of you guys have a look and see if I'm going in the right
                >>>>direction ?
                >>>>The few classes (put in a single file for the sake of easy reading)
                >>>>can be found here:http://web-develop.nl/user_oop.phps
                >>>>Hope you guys can give me some useful comments.
                >>>The thing I like most, Yorian, is that it is well formatted! I don't
                >>>know
                >>>what language the comments are in, however I do recognize 'singleton'.
                >>>For
                >>>the classes that are singletons, you need to make the __constructor a
                >>>private function and use the 'static' keyword for the other
                >>>functions/variables in the class. You'd necissarily need a way to supply
                >>>those singletons the constructor args. You can either let the caller set
                >>>the
                >>>values via 'setters' and/or create a static function, like 'initialize',
                >>>that essentially carries out the responsibility of __construct. You
                >>>should
                >>>also think about defining __clone, __copy, etc. specifically as private
                >>>so
                >>>that you are guaranteed not to have more than one instance of the
                >>>singleton.
                >>>Again, I like the code most because I can readily tell what it is
                >>>doing...beca use it is well formatted. Above all, that will save time,
                >>>money,
                >>>and frustration when you need to add to it or modify it in some way in
                >>>the
                >>>future.
                >>>Cheers
                >>Instead of using all of those getAttribute methods, you could use a
                >>generic __get method that returns the attribute.
                >>Thomas
                >Ah, my fault, it's late. I meant that you can use __get to point to
                >those methods automatically using call_user_func. So that
                >$userInstanc e->last_name would call that method.
                >>
                >========
                >>
                >IMO, that's very bad advice. __get and __set only get executed when a caller
                >tries to access an *undefined* interface. You're abusing the actual intent
                >of __get/set. It makes it terribly hard to debug and manage. It doesn't
                >allow you to strongly type the input(s) or output(s). It's also a
                >performance hit. Further, you should notice tools like php documentor and
                >any screen dump of the object would not accurately show any validation for
                >the properties being set. I'd think about always being specific and not try
                >to rig the jury to obtain the get/set functionality that is supplied by
                >other oop languages. __get and __set are NOT php's version of other
                >languages' get/set construct.
                >
                Sorry, Python's my first language and this sort of thing works very
                cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                not quite ready for primetime.
                >
                Thomas
                In addition, the generic __get and __set methods are contrary to good OO
                design, even in Python.

                Part of good OO design is to keep separate things separate - that
                includes attributes. Independent getter and setter methods, while a
                paid to code, do this quite nicely. They also allow for easier
                validation/massage of the data. A single __get/__set method pair does
                not do this.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • 703designs

                  #9
                  Re: OOP php user system

                  On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                  703designs wrote:
                  On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                  "703designs " <thomasmal...@g mail.comwrote in message
                  >
                  >news:87a7979 2-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com....
                  On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                  >
                  >On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                  >>"Yorian" <yorianbenja... @hotmail.comwro te in message
                  >>>news:8b1c486 4-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                  >>>Hey,
                  >>>Although I've been using classes and object for quite a while now I've
                  >>>never actually programmed proper OO code yet. It ofcourse depends on
                  >>>what you call proper OO code. I have been seperating parts of the
                  >>>website. Like a user class, guestbook class, etc. But I've been
                  >>>putting all the code in one single class instead of of spreiding it..
                  >>>Since a short while I've been reading up on OOP and now I am tryingto
                  >>>actually do things the way they should be done to make a nice
                  >>>maintainab le module. Which in fact means that I'm trying to stick to
                  >>>some rules: Don't repeat yourself, seperation of concerns,
                  >>>encapsulatio n, etc.
                  >>>I've created (not finished just started it) a user system, this
                  >>>according to the mvc pattern. The names for the classes aren't perfect
                  >>>(user should actually be named userController, and userData should be
                  >>>named user, etc.).
                  >>>Could any of you guys have a look and see if I'm going in the right
                  >>>direction?
                  >>>The few classes (put in a single file for the sake of easy reading)
                  >>>can be found here:http://web-develop.nl/user_oop.phps
                  >>>Hope you guys can give me some useful comments.
                  >>The thing I like most, Yorian, is that it is well formatted! I don't
                  >>know
                  >>what language the comments are in, however I do recognize 'singleton'.
                  >>For
                  >>the classes that are singletons, you need to make the __constructor a
                  >>private function and use the 'static' keyword for the other
                  >>functions/variables in the class. You'd necissarily need a way to supply
                  >>those singletons the constructor args. You can either let the callerset
                  >>the
                  >>values via 'setters' and/or create a static function, like 'initialize',
                  >>that essentially carries out the responsibility of __construct. You
                  >>should
                  >>also think about defining __clone, __copy, etc. specifically as private
                  >>so
                  >>that you are guaranteed not to have more than one instance of the
                  >>singleton.
                  >>Again, I like the code most because I can readily tell what it is
                  >>doing...becau se it is well formatted. Above all, that will save time,
                  >>money,
                  >>and frustration when you need to add to it or modify it in some way in
                  >>the
                  >>future.
                  >>Cheers
                  >Instead of using all of those getAttribute methods, you could use a
                  >generic __get method that returns the attribute.
                  >Thomas
                  Ah, my fault, it's late. I meant that you can use __get to point to
                  those methods automatically using call_user_func. So that
                  $userInstance->last_name would call that method.
                  >
                  ========
                  >
                  IMO, that's very bad advice. __get and __set only get executed when a caller
                  tries to access an *undefined* interface. You're abusing the actual intent
                  of __get/set. It makes it terribly hard to debug and manage. It doesn't
                  allow you to strongly type the input(s) or output(s). It's also a
                  performance hit. Further, you should notice tools like php documentor and
                  any screen dump of the object would not accurately show any validationfor
                  the properties being set. I'd think about always being specific and not try
                  to rig the jury to obtain the get/set functionality that is supplied by
                  other oop languages. __get and __set are NOT php's version of other
                  languages' get/set construct.
                  >
                  Sorry, Python's my first language and this sort of thing works very
                  cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                  not quite ready for primetime.
                  >
                  Thomas
                  >
                  In addition, the generic __get and __set methods are contrary to good OO
                  design, even in Python.
                  >
                  Part of good OO design is to keep separate things separate - that
                  includes attributes.  Independent getter and setter methods, while a
                  paid to code, do this quite nicely.  They also allow for easier
                  validation/massage of the data.  A single __get/__set method pair does
                  not do this.
                  >
                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstuck...@attgl obal.net
                  =============== ===
                  I never said that a single get/set pair should do that. Another part
                  of good OO design is to not reference object attributes directly, but
                  rather to always have getter and setter methods.

                  Thomas

                  Comment

                  • Jessica Griego

                    #10
                    Re: OOP php user system


                    "703designs " <thomasmallen@g mail.comwrote in message
                    news:45e468c4-d444-4a80-94e9-11a263b2a0dc@s1 g2000prg.google groups.com...
                    On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                    703designs wrote:
                    On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                    "703designs " <thomasmal...@g mail.comwrote in message
                    >
                    >news:87a7979 2-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                    On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                    >
                    >On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                    >>"Yorian" <yorianbenja... @hotmail.comwro te in message
                    >>>news:8b1c486 4-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                    >>>Hey,
                    >>>Although I've been using classes and object for quite a while now
                    >>>I've
                    >>>never actually programmed proper OO code yet. It ofcourse depends on
                    >>>what you call proper OO code. I have been seperating parts of the
                    >>>website. Like a user class, guestbook class, etc. But I've been
                    >>>putting all the code in one single class instead of of spreiding it.
                    >>>Since a short while I've been reading up on OOP and now I am trying
                    >>>to
                    >>>actually do things the way they should be done to make a nice
                    >>>maintainab le module. Which in fact means that I'm trying to stick to
                    >>>some rules: Don't repeat yourself, seperation of concerns,
                    >>>encapsulatio n, etc.
                    >>>I've created (not finished just started it) a user system, this
                    >>>according to the mvc pattern. The names for the classes aren't
                    >>>perfect
                    >>>(user should actually be named userController, and userData should
                    >>>be
                    >>>named user, etc.).
                    >>>Could any of you guys have a look and see if I'm going in the right
                    >>>direction?
                    >>>The few classes (put in a single file for the sake of easy reading)
                    >>>can be found here:http://web-develop.nl/user_oop.phps
                    >>>Hope you guys can give me some useful comments.
                    >>The thing I like most, Yorian, is that it is well formatted! I don't
                    >>know
                    >>what language the comments are in, however I do recognize
                    >>'singleton' .
                    >>For
                    >>the classes that are singletons, you need to make the __constructor a
                    >>private function and use the 'static' keyword for the other
                    >>functions/variables in the class. You'd necissarily need a way to
                    >>supply
                    >>those singletons the constructor args. You can either let the caller
                    >>set
                    >>the
                    >>values via 'setters' and/or create a static function, like
                    >>'initialize ',
                    >>that essentially carries out the responsibility of __construct. You
                    >>should
                    >>also think about defining __clone, __copy, etc. specifically as
                    >>private
                    >>so
                    >>that you are guaranteed not to have more than one instance of the
                    >>singleton.
                    >>Again, I like the code most because I can readily tell what it is
                    >>doing...becau se it is well formatted. Above all, that will save time,
                    >>money,
                    >>and frustration when you need to add to it or modify it in some way
                    >>in
                    >>the
                    >>future.
                    >>Cheers
                    >Instead of using all of those getAttribute methods, you could use a
                    >generic __get method that returns the attribute.
                    >Thomas
                    Ah, my fault, it's late. I meant that you can use __get to point to
                    those methods automatically using call_user_func. So that
                    $userInstance->last_name would call that method.
                    >
                    ========
                    >
                    IMO, that's very bad advice. __get and __set only get executed when a
                    caller
                    tries to access an *undefined* interface. You're abusing the actual
                    intent
                    of __get/set. It makes it terribly hard to debug and manage. It doesn't
                    allow you to strongly type the input(s) or output(s). It's also a
                    performance hit. Further, you should notice tools like php documentor
                    and
                    any screen dump of the object would not accurately show any validation
                    for
                    the properties being set. I'd think about always being specific and not
                    try
                    to rig the jury to obtain the get/set functionality that is supplied by
                    other oop languages. __get and __set are NOT php's version of other
                    languages' get/set construct.
                    >
                    Sorry, Python's my first language and this sort of thing works very
                    cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                    not quite ready for primetime.
                    >
                    Thomas
                    >
                    In addition, the generic __get and __set methods are contrary to good OO
                    design, even in Python.
                    >
                    Part of good OO design is to keep separate things separate - that
                    includes attributes. Independent getter and setter methods, while a
                    paid to code, do this quite nicely. They also allow for easier
                    validation/massage of the data. A single __get/__set method pair does
                    not do this.
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstuck...@attgl obal.net
                    =============== ===
                    I never said that a single get/set pair should do that. Another part
                    of good OO design is to not reference object attributes directly, but
                    rather to always have getter and setter methods.

                    =======

                    Hey Thomas. I don't think that's what Jerry is saying. In your suggested
                    implementation, all caller access to interfaces would come through __get and
                    __set. He assumes all of your validation would be contained in one single
                    and potentially large function (either __get or _set). What he fails to
                    realize, or give you credit for, is the fact that you very well could have
                    getters and settered defined in your object...either made public or private.
                    __get and __set could merely have a switch statement that defers the input
                    arguments to those getters/setter you have defined - which in fact *are*
                    independent. This scenario is outside of Jerry's criticism as things are
                    kept separate. It was just a bad assumption on his part.

                    My comment was, and still is, that __get/__set in php is meant to work in
                    the opposite way that other OOP languages use them - php uses them for
                    undefined interface references made by a caller.

                    As for Jerry's take on __get/__set in other languages, most bind them to the
                    specific interface...i.e .

                    Public Property Foo As Boolean
                    Get Foo() As Boolean
                    Return myFoo
                    End Get
                    Set Foo(ByVal Value As Boolean)
                    myFoo = Value
                    End Set
                    End Property

                    I just get the impression that Jerry doesn't work with many other
                    languages...eno ugh to not make such a silly statement.

                    Cheers, Thomas


                    Comment

                    • 703designs

                      #11
                      Re: OOP php user system

                      On Nov 10, 9:45 am, "Jessica Griego" <j...@example.c omwrote:
                      "703designs " <thomasmal...@g mail.comwrote in message
                      >
                      news:45e468c4-d444-4a80-94e9-11a263b2a0dc@s1 g2000prg.google groups.com...
                      On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      >
                      >
                      >
                      703designs wrote:
                      On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                      >"703designs " <thomasmal...@g mail.comwrote in message
                      >
                      >>news:87a797 92-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                      >On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                      >
                      >>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                      >>>"Yorian" <yorianbenja... @hotmail.comwro te in message
                      >>>>news:8b1c48 64-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                      >>>>Hey,
                      >>>>Although I've been using classes and object for quite a while now
                      >>>>I've
                      >>>>never actually programmed proper OO code yet. It ofcourse dependson
                      >>>>what you call proper OO code. I have been seperating parts of the
                      >>>>website. Like a user class, guestbook class, etc. But I've been
                      >>>>putting all the code in one single class instead of of spreiding it.
                      >>>>Since a short while I've been reading up on OOP and now I am trying
                      >>>>to
                      >>>>actually do things the way they should be done to make a nice
                      >>>>maintainabl e module. Which in fact means that I'm trying to stickto
                      >>>>some rules: Don't repeat yourself, seperation of concerns,
                      >>>>encapsulati on, etc.
                      >>>>I've created (not finished just started it) a user system, this
                      >>>>according to the mvc pattern. The names for the classes aren't
                      >>>>perfect
                      >>>>(user should actually be named userController, and userData should
                      >>>>be
                      >>>>named user, etc.).
                      >>>>Could any of you guys have a look and see if I'm going in the right
                      >>>>direction ?
                      >>>>The few classes (put in a single file for the sake of easy reading)
                      >>>>can be found here:http://web-develop.nl/user_oop.phps
                      >>>>Hope you guys can give me some useful comments.
                      >>>The thing I like most, Yorian, is that it is well formatted! I don't
                      >>>know
                      >>>what language the comments are in, however I do recognize
                      >>>'singleton '.
                      >>>For
                      >>>the classes that are singletons, you need to make the __constructor a
                      >>>private function and use the 'static' keyword for the other
                      >>>functions/variables in the class. You'd necissarily need a way to
                      >>>supply
                      >>>those singletons the constructor args. You can either let the caller
                      >>>set
                      >>>the
                      >>>values via 'setters' and/or create a static function, like
                      >>>'initialize' ,
                      >>>that essentially carries out the responsibility of __construct. You
                      >>>should
                      >>>also think about defining __clone, __copy, etc. specifically as
                      >>>private
                      >>>so
                      >>>that you are guaranteed not to have more than one instance of the
                      >>>singleton.
                      >>>Again, I like the code most because I can readily tell what it is
                      >>>doing...beca use it is well formatted. Above all, that will save time,
                      >>>money,
                      >>>and frustration when you need to add to it or modify it in some way
                      >>>in
                      >>>the
                      >>>future.
                      >>>Cheers
                      >>Instead of using all of those getAttribute methods, you could use a
                      >>generic __get method that returns the attribute.
                      >>Thomas
                      >Ah, my fault, it's late. I meant that you can use __get to point to
                      >those methods automatically using call_user_func. So that
                      >$userInstanc e->last_name would call that method.
                      >
                      >========
                      >
                      >IMO, that's very bad advice. __get and __set only get executed when a
                      >caller
                      >tries to access an *undefined* interface. You're abusing the actual
                      >intent
                      >of __get/set. It makes it terribly hard to debug and manage. It doesn't
                      >allow you to strongly type the input(s) or output(s). It's also a
                      >performance hit. Further, you should notice tools like php documentor
                      >and
                      >any screen dump of the object would not accurately show any validation
                      >for
                      >the properties being set. I'd think about always being specific and not
                      >try
                      >to rig the jury to obtain the get/set functionality that is suppliedby
                      >other oop languages. __get and __set are NOT php's version of other
                      >languages' get/set construct.
                      >
                      Sorry, Python's my first language and this sort of thing works very
                      cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                      not quite ready for primetime.
                      >
                      Thomas
                      >
                      In addition, the generic __get and __set methods are contrary to good OO
                      design, even in Python.
                      >
                      Part of good OO design is to keep separate things separate - that
                      includes attributes. Independent getter and setter methods, while a
                      paid to code, do this quite nicely. They also allow for easier
                      validation/massage of the data. A single __get/__set method pair does
                      not do this.
                      >
                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstuck...@attgl obal.net
                      =============== ===
                      >
                      I never said that a single get/set pair should do that. Another part
                      of good OO design is to not reference object attributes directly, but
                      rather to always have getter and setter methods.
                      >
                      =======
                      >
                      Hey Thomas. I don't think that's what Jerry is saying. In your suggested
                      implementation, all caller access to interfaces would come through __get and
                      __set. He assumes all of your validation would be contained in one single
                      and potentially large function (either __get or _set). What he fails to
                      realize, or give you credit for, is the fact that you very well could have
                      getters and settered defined in your object...either made public or private.
                      __get and __set could merely have a switch statement that defers the input
                      arguments to those getters/setter you have defined - which in fact *are*
                      independent. This scenario is outside of Jerry's criticism as things are
                      kept separate. It was just a bad assumption on his part.
                      >
                      My comment was, and still is, that __get/__set in php is meant to work in
                      the opposite way that other OOP languages use them - php uses them for
                      undefined interface references made by a caller.
                      >
                      As for Jerry's take on __get/__set in other languages, most bind them to the
                      specific interface...i.e .
                      >
                      Public Property Foo As Boolean
                        Get Foo() As Boolean
                          Return myFoo
                        End Get
                        Set Foo(ByVal Value As Boolean)
                          myFoo = Value
                        End Set
                      End Property
                      >
                      I just get the impression that Jerry doesn't work with many other
                      languages...eno ugh to not make such a silly statement.
                      >
                      Cheers, Thomas
                      Right, I think Jerry missed the part of my recommendation of calling
                      call_user_func( method) in __get. Getter and setter methods would still
                      be abound.

                      Thanks,
                      Thomas

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: OOP php user system

                        703designs wrote:
                        On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                        >703designs wrote:
                        >>On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                        >>>"703design s" <thomasmal...@g mail.comwrote in message
                        >>>news:87a7979 2-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                        >>>On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                        >>>>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                        >>>>>"Yorian" <yorianbenja... @hotmail.comwro te in message
                        >>>>>news:8b1c4 864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                        >>>>>>Hey,
                        >>>>>>Althoug h I've been using classes and object for quite a while now I've
                        >>>>>>never actually programmed proper OO code yet. It ofcourse depends on
                        >>>>>>what you call proper OO code. I have been seperating parts of the
                        >>>>>>website . Like a user class, guestbook class, etc. But I've been
                        >>>>>>putting all the code in one single class instead of of spreiding it.
                        >>>>>>Since a short while I've been reading up on OOP and now I am trying to
                        >>>>>>actuall y do things the way they should be done to make a nice
                        >>>>>>maintaina ble module. Which in fact means that I'm trying to stick to
                        >>>>>>some rules: Don't repeat yourself, seperation of concerns,
                        >>>>>>encapsula tion, etc.
                        >>>>>>I've created (not finished just started it) a user system, this
                        >>>>>>accordi ng to the mvc pattern. The names for the classes aren't perfect
                        >>>>>>(user should actually be named userController, and userData should be
                        >>>>>>named user, etc.).
                        >>>>>>Could any of you guys have a look and see if I'm going in the right
                        >>>>>>direction ?
                        >>>>>>The few classes (put in a single file for the sake of easy reading)
                        >>>>>>can be found here:http://web-develop.nl/user_oop.phps
                        >>>>>>Hope you guys can give me some useful comments.
                        >>>>>The thing I like most, Yorian, is that it is well formatted! I don't
                        >>>>>know
                        >>>>>what language the comments are in, however I do recognize 'singleton'.
                        >>>>>For
                        >>>>>the classes that are singletons, you need to make the __constructor a
                        >>>>>private function and use the 'static' keyword for the other
                        >>>>>function s/variables in the class. You'd necissarily need a way to supply
                        >>>>>those singletons the constructor args. You can either let the caller set
                        >>>>>the
                        >>>>>values via 'setters' and/or create a static function, like 'initialize',
                        >>>>>that essentially carries out the responsibility of __construct. You
                        >>>>>should
                        >>>>>also think about defining __clone, __copy, etc. specifically as private
                        >>>>>so
                        >>>>>that you are guaranteed not to have more than one instance of the
                        >>>>>singleto n.
                        >>>>>Again, I like the code most because I can readily tell what it is
                        >>>>>doing...be cause it is well formatted. Above all, that will save time,
                        >>>>>money,
                        >>>>>and frustration when you need to add to it or modify it in some way in
                        >>>>>the
                        >>>>>future.
                        >>>>>Cheers
                        >>>>Instead of using all of those getAttribute methods, you could use a
                        >>>>generic __get method that returns the attribute.
                        >>>>Thomas
                        >>>Ah, my fault, it's late. I meant that you can use __get to point to
                        >>>those methods automatically using call_user_func. So that
                        >>>$userInstanc e->last_name would call that method.
                        >>>========
                        >>>IMO, that's very bad advice. __get and __set only get executed when a caller
                        >>>tries to access an *undefined* interface. You're abusing the actual intent
                        >>>of __get/set. It makes it terribly hard to debug and manage. It doesn't
                        >>>allow you to strongly type the input(s) or output(s). It's also a
                        >>>performanc e hit. Further, you should notice tools like php documentor and
                        >>>any screen dump of the object would not accurately show any validation for
                        >>>the properties being set. I'd think about always being specific and not try
                        >>>to rig the jury to obtain the get/set functionality that is supplied by
                        >>>other oop languages. __get and __set are NOT php's version of other
                        >>>languages' get/set construct.
                        >>Sorry, Python's my first language and this sort of thing works very
                        >>cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                        >>not quite ready for primetime.
                        >>Thomas
                        >In addition, the generic __get and __set methods are contrary to good OO
                        >design, even in Python.
                        >>
                        >Part of good OO design is to keep separate things separate - that
                        >includes attributes. Independent getter and setter methods, while a
                        >paid to code, do this quite nicely. They also allow for easier
                        >validation/massage of the data. A single __get/__set method pair does
                        >not do this.
                        >>
                        >--
                        >============== ====
                        >Remove the "x" from my email address
                        >Jerry Stuckle
                        >JDS Computer Training Corp.
                        >jstuck...@attg lobal.net
                        >============== ====
                        >
                        I never said that a single get/set pair should do that. Another part
                        of good OO design is to not reference object attributes directly, but
                        rather to always have getter and setter methods.
                        >
                        Thomas
                        Then if each attribute has it's own get/set pair (as in good OO design),
                        there is no need for the __get/__set methods.

                        That's why you won't find them in good OO languages such as SmallTalk,
                        Java and even C++.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • Jessica Griego

                          #13
                          Re: OOP php user system


                          "703designs " <thomasmallen@g mail.comwrote in message
                          news:e6f2d6a9-1ab8-441d-b6cf-1d63c6b94908@a1 7g2000prm.googl egroups.com...
                          On Nov 10, 9:45 am, "Jessica Griego" <j...@example.c omwrote:
                          "703designs " <thomasmal...@g mail.comwrote in message
                          >
                          news:45e468c4-d444-4a80-94e9-11a263b2a0dc@s1 g2000prg.google groups.com...
                          On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                          >
                          >
                          >
                          703designs wrote:
                          On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                          >"703designs " <thomasmal...@g mail.comwrote in message
                          >
                          >>news:87a797 92-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                          >On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                          >
                          >>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                          >>>"Yorian" <yorianbenja... @hotmail.comwro te in message
                          >>>>news:8b1c48 64-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                          >>>>Hey,
                          >>>>Although I've been using classes and object for quite a while now
                          >>>>I've
                          >>>>never actually programmed proper OO code yet. It ofcourse depends
                          >>>>on
                          >>>>what you call proper OO code. I have been seperating parts of the
                          >>>>website. Like a user class, guestbook class, etc. But I've been
                          >>>>putting all the code in one single class instead of of spreiding
                          >>>>it.
                          >>>>Since a short while I've been reading up on OOP and now I am
                          >>>>trying
                          >>>>to
                          >>>>actually do things the way they should be done to make a nice
                          >>>>maintainabl e module. Which in fact means that I'm trying to stick
                          >>>>to
                          >>>>some rules: Don't repeat yourself, seperation of concerns,
                          >>>>encapsulati on, etc.
                          >>>>I've created (not finished just started it) a user system, this
                          >>>>according to the mvc pattern. The names for the classes aren't
                          >>>>perfect
                          >>>>(user should actually be named userController, and userData should
                          >>>>be
                          >>>>named user, etc.).
                          >>>>Could any of you guys have a look and see if I'm going in the
                          >>>>right
                          >>>>direction ?
                          >>>>The few classes (put in a single file for the sake of easy
                          >>>>reading)
                          >>>>can be found here:http://web-develop.nl/user_oop.phps
                          >>>>Hope you guys can give me some useful comments.
                          >>>The thing I like most, Yorian, is that it is well formatted! I
                          >>>don't
                          >>>know
                          >>>what language the comments are in, however I do recognize
                          >>>'singleton '.
                          >>>For
                          >>>the classes that are singletons, you need to make the __constructor
                          >>>a
                          >>>private function and use the 'static' keyword for the other
                          >>>functions/variables in the class. You'd necissarily need a way to
                          >>>supply
                          >>>those singletons the constructor args. You can either let the
                          >>>caller
                          >>>set
                          >>>the
                          >>>values via 'setters' and/or create a static function, like
                          >>>'initialize' ,
                          >>>that essentially carries out the responsibility of __construct. You
                          >>>should
                          >>>also think about defining __clone, __copy, etc. specifically as
                          >>>private
                          >>>so
                          >>>that you are guaranteed not to have more than one instance of the
                          >>>singleton.
                          >>>Again, I like the code most because I can readily tell what it is
                          >>>doing...beca use it is well formatted. Above all, that will save
                          >>>time,
                          >>>money,
                          >>>and frustration when you need to add to it or modify it in some way
                          >>>in
                          >>>the
                          >>>future.
                          >>>Cheers
                          >>Instead of using all of those getAttribute methods, you could use a
                          >>generic __get method that returns the attribute.
                          >>Thomas
                          >Ah, my fault, it's late. I meant that you can use __get to point to
                          >those methods automatically using call_user_func. So that
                          >$userInstanc e->last_name would call that method.
                          >
                          >========
                          >
                          >IMO, that's very bad advice. __get and __set only get executed when a
                          >caller
                          >tries to access an *undefined* interface. You're abusing the actual
                          >intent
                          >of __get/set. It makes it terribly hard to debug and manage. It
                          >doesn't
                          >allow you to strongly type the input(s) or output(s). It's also a
                          >performance hit. Further, you should notice tools like php documentor
                          >and
                          >any screen dump of the object would not accurately show any
                          >validation
                          >for
                          >the properties being set. I'd think about always being specific and
                          >not
                          >try
                          >to rig the jury to obtain the get/set functionality that is supplied
                          >by
                          >other oop languages. __get and __set are NOT php's version of other
                          >languages' get/set construct.
                          >
                          Sorry, Python's my first language and this sort of thing works very
                          cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                          not quite ready for primetime.
                          >
                          Thomas
                          >
                          In addition, the generic __get and __set methods are contrary to good OO
                          design, even in Python.
                          >
                          Part of good OO design is to keep separate things separate - that
                          includes attributes. Independent getter and setter methods, while a
                          paid to code, do this quite nicely. They also allow for easier
                          validation/massage of the data. A single __get/__set method pair does
                          not do this.
                          >
                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstuck...@attgl obal.net
                          =============== ===
                          >
                          I never said that a single get/set pair should do that. Another part
                          of good OO design is to not reference object attributes directly, but
                          rather to always have getter and setter methods.
                          >
                          =======
                          >
                          Hey Thomas. I don't think that's what Jerry is saying. In your suggested
                          implementation, all caller access to interfaces would come through __get
                          and
                          __set. He assumes all of your validation would be contained in one single
                          and potentially large function (either __get or _set). What he fails to
                          realize, or give you credit for, is the fact that you very well could have
                          getters and settered defined in your object...either made public or
                          private.
                          __get and __set could merely have a switch statement that defers the input
                          arguments to those getters/setter you have defined - which in fact *are*
                          independent. This scenario is outside of Jerry's criticism as things are
                          kept separate. It was just a bad assumption on his part.
                          >
                          My comment was, and still is, that __get/__set in php is meant to work in
                          the opposite way that other OOP languages use them - php uses them for
                          undefined interface references made by a caller.
                          >
                          As for Jerry's take on __get/__set in other languages, most bind them to
                          the
                          specific interface...i.e .
                          >
                          Public Property Foo As Boolean
                          Get Foo() As Boolean
                          Return myFoo
                          End Get
                          Set Foo(ByVal Value As Boolean)
                          myFoo = Value
                          End Set
                          End Property
                          >
                          I just get the impression that Jerry doesn't work with many other
                          languages...eno ugh to not make such a silly statement.
                          >
                          Cheers, Thomas
                          Right, I think Jerry missed the part of my recommendation of calling
                          call_user_func( method) in __get. Getter and setter methods would still
                          be abound.

                          =========

                          Bingo!

                          And, my take on Jerry is that he likes to assume he is correct, without ever
                          actually being correct. The nature of a troll I suppose. :^)


                          Comment

                          • 703designs

                            #14
                            Re: OOP php user system

                            On Nov 10, 10:17 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            703designs wrote:
                            On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            703designs wrote:
                            >On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                            >>"703designs " <thomasmal...@g mail.comwrote in message
                            >>>news:87a7979 2-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                            >>On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                            >>>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                            >>>>"Yorian" <yorianbenja... @hotmail.comwro te in message
                            >>>>>news:8b1c4 864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                            >>>>>Hey,
                            >>>>>Although I've been using classes and object for quite a while nowI've
                            >>>>>never actually programmed proper OO code yet. It ofcourse dependson
                            >>>>>what you call proper OO code. I have been seperating parts of the
                            >>>>>website. Like a user class, guestbook class, etc. But I've been
                            >>>>>putting all the code in one single class instead of of spreiding it.
                            >>>>>Since a short while I've been reading up on OOP and now I am trying to
                            >>>>>actually do things the way they should be done to make a nice
                            >>>>>maintainab le module. Which in fact means that I'm trying to stickto
                            >>>>>some rules: Don't repeat yourself, seperation of concerns,
                            >>>>>encapsulat ion, etc.
                            >>>>>I've created (not finished just started it) a user system, this
                            >>>>>accordin g to the mvc pattern. The names for the classes aren't perfect
                            >>>>>(user should actually be named userController, and userData should be
                            >>>>>named user, etc.).
                            >>>>>Could any of you guys have a look and see if I'm going in the right
                            >>>>>directio n?
                            >>>>>The few classes (put in a single file for the sake of easy reading)
                            >>>>>can be found here:http://web-develop.nl/user_oop.phps
                            >>>>>Hope you guys can give me some useful comments.
                            >>>>The thing I like most, Yorian, is that it is well formatted! I don't
                            >>>>know
                            >>>>what language the comments are in, however I do recognize 'singleton'.
                            >>>>For
                            >>>>the classes that are singletons, you need to make the __constructor a
                            >>>>private function and use the 'static' keyword for the other
                            >>>>functions/variables in the class. You'd necissarily need a way to supply
                            >>>>those singletons the constructor args. You can either let the caller set
                            >>>>the
                            >>>>values via 'setters' and/or create a static function, like 'initialize',
                            >>>>that essentially carries out the responsibility of __construct. You
                            >>>>should
                            >>>>also think about defining __clone, __copy, etc. specifically as private
                            >>>>so
                            >>>>that you are guaranteed not to have more than one instance of the
                            >>>>singleton .
                            >>>>Again, I like the code most because I can readily tell what it is
                            >>>>doing...bec ause it is well formatted. Above all, that will save time,
                            >>>>money,
                            >>>>and frustration when you need to add to it or modify it in some way in
                            >>>>the
                            >>>>future.
                            >>>>Cheers
                            >>>Instead of using all of those getAttribute methods, you could use a
                            >>>generic __get method that returns the attribute.
                            >>>Thomas
                            >>Ah, my fault, it's late. I meant that you can use __get to point to
                            >>those methods automatically using call_user_func. So that
                            >>$userInstan ce->last_name would call that method.
                            >>========
                            >>IMO, that's very bad advice. __get and __set only get executed when a caller
                            >>tries to access an *undefined* interface. You're abusing the actual intent
                            >>of __get/set. It makes it terribly hard to debug and manage. It doesn't
                            >>allow you to strongly type the input(s) or output(s). It's also a
                            >>performance hit. Further, you should notice tools like php documentor and
                            >>any screen dump of the object would not accurately show any validation for
                            >>the properties being set. I'd think about always being specific and not try
                            >>to rig the jury to obtain the get/set functionality that is suppliedby
                            >>other oop languages. __get and __set are NOT php's version of other
                            >>languages' get/set construct.
                            >Sorry, Python's my first language and this sort of thing works very
                            >cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                            >not quite ready for primetime.
                            >Thomas
                            In addition, the generic __get and __set methods are contrary to good OO
                            design, even in Python.
                            >
                            Part of good OO design is to keep separate things separate - that
                            includes attributes.  Independent getter and setter methods, while a
                            paid to code, do this quite nicely.  They also allow for easier
                            validation/massage of the data.  A single __get/__set method pair does
                            not do this.
                            >
                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstuck...@attgl obal.net
                            =============== ===
                            >
                            I never said that a single get/set pair should do that. Another part
                            of good OO design is to not reference object attributes directly, but
                            rather to always have getter and setter methods.
                            >
                            Thomas
                            >
                            Then if each attribute has it's own get/set pair (as in good OO design),
                            there is no need for the __get/__set methods.
                            >
                            That's why you won't find them in good OO languages such as SmallTalk,
                            Java and even C++.
                            >
                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstuck...@attgl obal.net
                            =============== ===
                            If my application design is such that getting and setting will
                            probably be required in the future, I can avoid massive refactoring by
                            mapping assignment to __set and retrieval to __get. That way, in the
                            early stages I can use:

                            echo $this->name;

                            and even if it's used site-wide, I can instantly map all of these
                            references to $this->getName() if I use __get properly.

                            That is, if __get worked the way we wish it did :^)

                            You should check out Manning Press' "PHP in Action." It has some top-
                            notch writing on this subject. Their recommendation is the same as
                            Jessica's (that __get's not designed/implemented appropriately for
                            this use quite yet).

                            Thanks,
                            Thomas

                            Comment

                            • Jessica Griego

                              #15
                              Re: OOP php user system


                              "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                              news:gf9jet$nn4 $2@registered.m otzarella.org.. .
                              703designs wrote:
                              >On Nov 10, 6:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                              >>703designs wrote:
                              >>>On Nov 9, 11:28 pm, "Jessica Griego" <j...@example.c omwrote:
                              >>>>"703designs " <thomasmal...@g mail.comwrote in message
                              >>>>news:87a797 92-c2b5-477a-8376-774d3951453f@a2 6g2000prf.googl egroups.com...
                              >>>>On Nov 9, 10:46 pm, 703designs <thomasmal...@g mail.comwrote:
                              >>>>>On Nov 9, 10:37 pm, "Jessica Griego" <j...@example.c omwrote:
                              >>>>>>"Yorian " <yorianbenja... @hotmail.comwro te in message
                              >>>>>>news:8b1c 4864-385d-45fa-bb75-3b9d2b736532@t3 9g2000prh.googl egroups.com...
                              >>>>>>>Hey,
                              >>>>>>>Althou gh I've been using classes and object for quite a while now
                              >>>>>>>I've
                              >>>>>>>never actually programmed proper OO code yet. It ofcourse depends
                              >>>>>>>on
                              >>>>>>>what you call proper OO code. I have been seperating parts of the
                              >>>>>>>websit e. Like a user class, guestbook class, etc. But I've been
                              >>>>>>>puttin g all the code in one single class instead of of spreiding
                              >>>>>>>it.
                              >>>>>>>Since a short while I've been reading up on OOP and now I am trying
                              >>>>>>>to
                              >>>>>>>actual ly do things the way they should be done to make a nice
                              >>>>>>>maintain able module. Which in fact means that I'm trying to stick
                              >>>>>>>to
                              >>>>>>>some rules: Don't repeat yourself, seperation of concerns,
                              >>>>>>>encapsul ation, etc.
                              >>>>>>>I've created (not finished just started it) a user system, this
                              >>>>>>>accordin g to the mvc pattern. The names for the classes aren't
                              >>>>>>>perfec t
                              >>>>>>>(user should actually be named userController, and userData should
                              >>>>>>>be
                              >>>>>>>named user, etc.).
                              >>>>>>>Could any of you guys have a look and see if I'm going in the right
                              >>>>>>>directio n?
                              >>>>>>>The few classes (put in a single file for the sake of easy reading)
                              >>>>>>>can be found here:http://web-develop.nl/user_oop.phps
                              >>>>>>>Hope you guys can give me some useful comments.
                              >>>>>>The thing I like most, Yorian, is that it is well formatted! I don't
                              >>>>>>know
                              >>>>>>what language the comments are in, however I do recognize
                              >>>>>>'singleto n'.
                              >>>>>>For
                              >>>>>>the classes that are singletons, you need to make the __constructor
                              >>>>>>a
                              >>>>>>private function and use the 'static' keyword for the other
                              >>>>>>functio ns/variables in the class. You'd necissarily need a way to
                              >>>>>>supply
                              >>>>>>those singletons the constructor args. You can either let the caller
                              >>>>>>set
                              >>>>>>the
                              >>>>>>values via 'setters' and/or create a static function, like
                              >>>>>>'initiali ze',
                              >>>>>>that essentially carries out the responsibility of __construct. You
                              >>>>>>should
                              >>>>>>also think about defining __clone, __copy, etc. specifically as
                              >>>>>>private
                              >>>>>>so
                              >>>>>>that you are guaranteed not to have more than one instance of the
                              >>>>>>singleton .
                              >>>>>>Again, I like the code most because I can readily tell what it is
                              >>>>>>doing...b ecause it is well formatted. Above all, that will save
                              >>>>>>time,
                              >>>>>>money,
                              >>>>>>and frustration when you need to add to it or modify it in some way
                              >>>>>>in
                              >>>>>>the
                              >>>>>>future.
                              >>>>>>Cheers
                              >>>>>Instead of using all of those getAttribute methods, you could use a
                              >>>>>generic __get method that returns the attribute.
                              >>>>>Thomas
                              >>>>Ah, my fault, it's late. I meant that you can use __get to point to
                              >>>>those methods automatically using call_user_func. So that
                              >>>>$userInstan ce->last_name would call that method.
                              >>>>========
                              >>>>IMO, that's very bad advice. __get and __set only get executed when a
                              >>>>caller
                              >>>>tries to access an *undefined* interface. You're abusing the actual
                              >>>>intent
                              >>>>of __get/set. It makes it terribly hard to debug and manage. It
                              >>>>doesn't
                              >>>>allow you to strongly type the input(s) or output(s). It's also a
                              >>>>performan ce hit. Further, you should notice tools like php documentor
                              >>>>and
                              >>>>any screen dump of the object would not accurately show any validation
                              >>>>for
                              >>>>the properties being set. I'd think about always being specific and
                              >>>>not try
                              >>>>to rig the jury to obtain the get/set functionality that is supplied
                              >>>>by
                              >>>>other oop languages. __get and __set are NOT php's version of other
                              >>>>languages ' get/set construct.
                              >>>Sorry, Python's my first language and this sort of thing works very
                              >>>cleanly there. I'll keep these drawbacks in mind: I guess that __get's
                              >>>not quite ready for primetime.
                              >>>Thomas
                              >>In addition, the generic __get and __set methods are contrary to good OO
                              >>design, even in Python.
                              >>>
                              >>Part of good OO design is to keep separate things separate - that
                              >>includes attributes. Independent getter and setter methods, while a
                              >>paid to code, do this quite nicely. They also allow for easier
                              >>validation/massage of the data. A single __get/__set method pair does
                              >>not do this.
                              >>>
                              >>--
                              >>============= =====
                              >>Remove the "x" from my email address
                              >>Jerry Stuckle
                              >>JDS Computer Training Corp.
                              >>jstuck...@att global.net
                              >>============= =====
                              >>
                              >I never said that a single get/set pair should do that. Another part
                              >of good OO design is to not reference object attributes directly, but
                              >rather to always have getter and setter methods.
                              >>
                              >Thomas
                              >
                              Then if each attribute has it's own get/set pair (as in good OO design),
                              there is no need for the __get/__set methods.
                              >
                              That's why you won't find them in good OO languages such as SmallTalk,
                              Java and even C++.
                              Jerry, Jerry, Jerry!

                              The 'need' could be as simple as convenience! OOP languages bind getters and
                              setters directly into the properties available to the caller...such that:

                              object.property = something // initiates a __set

                              and

                              print object.property // initiates a __get

                              That's not so hard to understand! And while Java and C++ fit the bill, I
                              hardly would hold SmallTalk up as a beacon for OOP! However, ALL of those
                              languages operate in the way I've just displayed. Thomas is simply trying to
                              coerse php to do what the rest of us hope it eventually will...give us the
                              same or similar constructs.

                              BTW, quit accusing Thomas of bad design! If you read his suggestion, you'd
                              have noticed that he's not balling up all of his validation in __get/set as
                              you've twice accused him of. He suggested using php's call user func
                              function...I said it could be as easy as a switch statement and a direct
                              call to the getter/setter. Thus far, your arguments are MOOT. You've only to
                              state that "there is no need for the __get/__set methods" (if you've already
                              defined getters/setters). Ok then! Statement noted.

                              Do you ever offer advice that actually further's someone's understanding of
                              php or help better the content of a thread in which you've posted, Jerry? I
                              can't see that you do.


                              Comment

                              Working...