Object Oriented PHP

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

    #16
    Re: Object Oriented PHP

    Jerry Stuckle wrote:[color=blue]
    > IchBin wrote:[color=green]
    >> David Haynes wrote:
    >>[color=darkred]
    >>> Tony Marston wrote:
    >>>
    >>>> "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
    >>>>
    >>>>> Actually, things like private declarations are very important.
    >>>>> They are unimportant only to those who don't understand OO
    >>>>> programming - or those who are sloppy in their implementations .
    >>>>
    >>>>
    >>>> You don't *need* private declarations. Code will work just as well
    >>>> without them.
    >>>>
    >>>
    >>> What the heck! Let's just throw away multiply and divide. We don't
    >>> *need* them. We can just use add and subtract.
    >>>
    >>> Heck! Why do we need subtract? We can just add negative values.
    >>>
    >>> Hey! Assembler works well without private declarations. Let's just
    >>> pitch PHP all together.
    >>>
    >>> The point is that constructs are added to language to assist in the
    >>> functionality and maintainability of programs written in that
    >>> language. The introduction of private and protected adds to the
    >>> maintainability both through its inherent protection capabilities and
    >>> its clarity of intent for the maintainer.
    >>>
    >>> Now if PHP could just get polymorphism...
    >>>
    >>> -david-
    >>>[/color]
    >>
    >> Sorry I am new to PHP but use Java. My question is how can you have a
    >> OOP Language and not have polymorphic features. Sorry, I have not
    >> gotten up to par on PHP yet.
    >>
    >> Thanks in Advance...
    >> IchBin, Pocono Lake, Pa, USA http://weconsultants.awardspace.com
    >> _______________ _______________ _______________ _______________ ______________
    >>
    >>
    >> 'If there is one, Knowledge is the "Fountain of Youth"'
    >> -William E. Taylor, Regular Guy (1952-)[/color]
    >
    > PHP does have some polymorphic-like abilities, but that's because of the
    > untyped nature of the variables.
    >
    > PHP is getting better in it's OO aspects, but I doubt it will ever be
    > quite like Java. There's just a basic difference between languages with
    > typed and untyped variables.
    >
    >[/color]
    Thanks for the info..

    I read something about PHP version 5, OOP\OOD and typed Objects. So I
    guess there are really not fully typed object. I have to read more and
    not take OOP references as used by say smalltalk and Java and others.

    --

    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA http://weconsultants.awardspace.com
    _______________ _______________ _______________ _______________ ______________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)

    Comment

    • David Haynes

      #17
      Re: Object Oriented PHP

      Jerry Stuckle wrote:[color=blue]
      > PHP does have some polymorphic-like abilities, but that's because of the
      > untyped nature of the variables.
      >
      > PHP is getting better in it's OO aspects, but I doubt it will ever be
      > quite like Java. There's just a basic difference between languages with
      > typed and untyped variables.[/color]

      I was thinking about this the other day and it may not be all that
      difficult to add it.

      Consider that you can already type the arguments to the constructor.
      Given this, it would not be all that hard to derive a typed signature
      which could then be applied.

      -david-

      Comment

      • Jerry Stuckle

        #18
        Re: Object Oriented PHP

        David Haynes wrote:[color=blue]
        > Jerry Stuckle wrote:
        >[color=green]
        >> PHP does have some polymorphic-like abilities, but that's because of
        >> the untyped nature of the variables.
        >>
        >> PHP is getting better in it's OO aspects, but I doubt it will ever be
        >> quite like Java. There's just a basic difference between languages
        >> with typed and untyped variables.[/color]
        >
        >
        > I was thinking about this the other day and it may not be all that
        > difficult to add it.
        >
        > Consider that you can already type the arguments to the constructor.
        > Given this, it would not be all that hard to derive a typed signature
        > which could then be applied.
        >
        > -david-
        >[/color]

        I really don't know how hard it would be to add - but I would like to see it
        added. One thing I don't like all that much is the untyped variables. It makes
        things "easy" - but leads to some sloppy programming.

        It also means you can't overload functions - at least not with the same number
        of parms. Typing the constructor arguments is a good start. But expanding that
        to other functions without breaking existing code might be more difficult.

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

        Comment

        • Tony Marston

          #19
          Re: Object Oriented PHP


          "David Haynes" <david.haynes2@ sympatico.ca> wrote in message
          news:Tvkng.2253 7$oG2.21662@fe2 6.usenetserver. com...[color=blue]
          > Tony Marston wrote:[color=green]
          >> "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message[color=darkred]
          >>> Actually, things like private declarations are very important. They are
          >>> unimportant only to those who don't understand OO programming - or those
          >>> who are sloppy in their implementations .[/color]
          >>
          >> You don't *need* private declarations. Code will work just as well
          >> without them.
          >>[/color]
          >
          > What the heck! Let's just throw away multiply and divide. We don't *need*
          > them. We can just use add and subtract.
          >
          > Heck! Why do we need subtract? We can just add negative values.
          >
          > Hey! Assembler works well without private declarations. Let's just pitch
          > PHP all together.
          >
          > The point is that constructs are added to language to assist in the
          > functionality and maintainability of programs written in that language.
          > The introduction of private and protected adds to the maintainability both
          > through its inherent protection capabilities and its clarity of intent for
          > the maintainer.
          >
          > Now if PHP could just get polymorphism...[/color]

          OOP with PHP already has polymorphism. You obviously don't know what
          polymorphism means.

          --
          Tony Marston

          This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

          RADICORE is a Rapid Application Development Toolkit for building Administrative Web Applications which are platform independent, browser independent and database independent.




          Comment

          • Tony Marston

            #20
            Re: Object Oriented PHP


            "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
            news:4K2dnSM18o D9YQDZnZ2dnUVZ_ oWdnZ2d@comcast .com...[color=blue]
            > David Haynes wrote:[color=green]
            >> Jerry Stuckle wrote:
            >>[/color][/color]
            < snip >
            [color=blue]
            > I really don't know how hard it would be to add - but I would like to see
            > it added. One thing I don't like all that much is the untyped variables.
            > It makes things "easy" - but leads to some sloppy programming.
            >
            > It also means you can't overload functions - at least not with the same
            > number of parms. Typing the constructor arguments is a good start. But
            > expanding that to other functions without breaking existing code might be
            > more difficult.[/color]

            You don't need function overloading in PHP. Why? First you need to look at
            why other languages need it:
            (a) To accept arguments of different types.
            (b) To make some arguments optional.

            With PHP you can accept an argument of any type and then cast it to the one
            you want, so item (a) is irrelevant.

            With PHP you can define a default value for an argument if it is not
            supplied, so item (b) is irrelevant.

            --
            Tony Marston

            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

            RADICORE is a Rapid Application Development Toolkit for building Administrative Web Applications which are platform independent, browser independent and database independent.




            Comment

            • David Haynes

              #21
              Re: Object Oriented PHP

              Tony Marston wrote:[color=blue]
              > "David Haynes" <david.haynes2@ sympatico.ca> wrote in message
              > news:Tvkng.2253 7$oG2.21662@fe2 6.usenetserver. com...[color=green]
              >> Tony Marston wrote:[color=darkred]
              >>> "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
              >>>> Actually, things like private declarations are very important. They are
              >>>> unimportant only to those who don't understand OO programming - or those
              >>>> who are sloppy in their implementations .
              >>> You don't *need* private declarations. Code will work just as well
              >>> without them.
              >>>[/color]
              >> What the heck! Let's just throw away multiply and divide. We don't *need*
              >> them. We can just use add and subtract.
              >>
              >> Heck! Why do we need subtract? We can just add negative values.
              >>
              >> Hey! Assembler works well without private declarations. Let's just pitch
              >> PHP all together.
              >>
              >> The point is that constructs are added to language to assist in the
              >> functionality and maintainability of programs written in that language.
              >> The introduction of private and protected adds to the maintainability both
              >> through its inherent protection capabilities and its clarity of intent for
              >> the maintainer.
              >>
              >> Now if PHP could just get polymorphism...[/color]
              >
              > OOP with PHP already has polymorphism. You obviously don't know what
              > polymorphism means.
              >[/color]
              Tony:

              PHP5 has weak polymorphism but not true polymorphism in the sense that
              it is used in OOP.

              You cannot, for instance, have multiple constructors for an object where
              the number of the arguments to the constructor are variable. Yes, you
              may supply default values to 'optional' arguments but consider this example:

              class Foo {
              function __construct($on e, $two="two", $three="three") {

              I cannot instantiate this object as new Foo($one, $three) since there is
              no typing on the arguments and, therefore, no signature for a 'one,
              three' contructor. Nor could I define multiple __constructor() methods
              to allow for the new Foo($one, $three) case.

              This type of action is common in other OOP languages such as Java and C++.

              To add to the confusion from an OOP programmer's viewpoint, in order to
              invoke the 'default' value for $three, I *must* supply a value for $two.
              That is, new Foo($one, , $three) is syntactically illegal and there is
              AFAIK no way to specify that we want $two to take its default value
              while supplying a value for $three.

              So, maybe its not me who is unclear on the concept of polymorphism...

              -david-

              Comment

              • Tim Van Wassenhove

                #22
                Re: Object Oriented PHP

                On 2006-06-25, David Haynes <david.haynes2@ sympatico.ca> wrote:[color=blue]
                > PHP5 has weak polymorphism but not true polymorphism in the sense that
                > it is used in OOP.[/color]

                So how would you define polymorphism? And what exactly are the
                differences between 'weak' and 'true' polymorphism?

                If i look at http://en.wikipedia.org/wiki/Polymor...ter_science%29

                "The concept of polymorphism applies to data types in addition to
                functions. A function that can evaluate to and be applied to values of
                different types is known as a polymorphic function. A data type that
                contains elements of different types is known as a polymorphic data
                type."
                [color=blue]
                > function __construct($on e, $two="two", $three="three") {
                >
                > I cannot instantiate this object as new Foo($one, $three) since there is
                > no typing on the arguments and, therefore, no signature for a 'one,
                > three' contructor.[/color]

                Imho that's the same as saying: I'm standing with my back against a wall,
                and now i'm wondering why i can't step backwards anymore...

                Define your constructor as __constructor($ args) and handle with
                func_num_args and func_get_args(s ) any number of parameters...

                (I do agree that the language/compiler can, probably should, make this
                easier... But that's a different discussion.)

                --
                Met vriendelijke groeten,
                Tim Van Wassenhove <http://timvw.madoka.be >

                Comment

                • Jerry Stuckle

                  #23
                  Re: Object Oriented PHP

                  Tony Marston wrote:[color=blue]
                  > "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                  > news:4K2dnSM18o D9YQDZnZ2dnUVZ_ oWdnZ2d@comcast .com...
                  >[color=green]
                  >>David Haynes wrote:
                  >>[color=darkred]
                  >>>Jerry Stuckle wrote:
                  >>>[/color][/color]
                  >
                  > < snip >
                  >[color=green]
                  >>I really don't know how hard it would be to add - but I would like to see
                  >>it added. One thing I don't like all that much is the untyped variables.
                  >>It makes things "easy" - but leads to some sloppy programming.
                  >>
                  >>It also means you can't overload functions - at least not with the same
                  >>number of parms. Typing the constructor arguments is a good start. But
                  >>expanding that to other functions without breaking existing code might be
                  >>more difficult.[/color]
                  >
                  >
                  > You don't need function overloading in PHP. Why? First you need to look at
                  > why other languages need it:
                  > (a) To accept arguments of different types.
                  > (b) To make some arguments optional.
                  >
                  > With PHP you can accept an argument of any type and then cast it to the one
                  > you want, so item (a) is irrelevant.
                  >
                  > With PHP you can define a default value for an argument if it is not
                  > supplied, so item (b) is irrelevant.
                  >[/color]

                  Sure. I would love to be able to have a function which does different things
                  based on the type of parameter passed. It would save a lot of work trying to
                  sort out parameters and potentially having to change existing code when adding
                  new parameter types.

                  But we already know you don't understand or appreciate real OO programming,
                  Tony. So quite frankly, I don't give a damn what you think.


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

                  Comment

                  • Jerry Stuckle

                    #24
                    Re: Object Oriented PHP

                    Tony Marston wrote:[color=blue]
                    > "David Haynes" <david.haynes2@ sympatico.ca> wrote in message
                    > news:Tvkng.2253 7$oG2.21662@fe2 6.usenetserver. com...
                    >[color=green]
                    >>Tony Marston wrote:
                    >>[color=darkred]
                    >>>"Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                    >>>
                    >>>>Actually, things like private declarations are very important. They are
                    >>>>unimporta nt only to those who don't understand OO programming - or those
                    >>>>who are sloppy in their implementations .
                    >>>
                    >>>You don't *need* private declarations. Code will work just as well
                    >>>without them.
                    >>>[/color]
                    >>
                    >>What the heck! Let's just throw away multiply and divide. We don't *need*
                    >>them. We can just use add and subtract.
                    >>
                    >>Heck! Why do we need subtract? We can just add negative values.
                    >>
                    >>Hey! Assembler works well without private declarations. Let's just pitch
                    >>PHP all together.
                    >>
                    >>The point is that constructs are added to language to assist in the
                    >>functionali ty and maintainability of programs written in that language.
                    >>The introduction of private and protected adds to the maintainability both
                    >>through its inherent protection capabilities and its clarity of intent for
                    >>the maintainer.
                    >>
                    >>Now if PHP could just get polymorphism...[/color]
                    >
                    >
                    > OOP with PHP already has polymorphism. You obviously don't know what
                    > polymorphism means.
                    >[/color]

                    No, Tony, you really don't know what polymorphism is, do you?

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

                    Comment

                    • David Haynes

                      #25
                      Re: Object Oriented PHP

                      Tim Van Wassenhove wrote:[color=blue]
                      > On 2006-06-25, David Haynes <david.haynes2@ sympatico.ca> wrote:[color=green]
                      >> PHP5 has weak polymorphism but not true polymorphism in the sense that
                      >> it is used in OOP.[/color]
                      >
                      > So how would you define polymorphism? And what exactly are the
                      > differences between 'weak' and 'true' polymorphism?
                      >
                      > If i look at http://en.wikipedia.org/wiki/Polymor...ter_science%29
                      >
                      > "The concept of polymorphism applies to data types in addition to
                      > functions. A function that can evaluate to and be applied to values of
                      > different types is known as a polymorphic function. A data type that
                      > contains elements of different types is known as a polymorphic data
                      > type."[/color]

                      Keep reading the article you referenced.

                      "This type of polymorphism [overloading] is common in object-oriented
                      programming languages, many of which allow operators to be overloaded in
                      a manner similar to functions (see operator overloading). It is also
                      used extensively in the purely functional programming language Haskell
                      in the form of type classes. Many languages lacking ad-hoc polymorphism
                      suffer from long-winded names such as print_int, print_string, etc. (see
                      C, Objective Caml)."
                      [color=blue][color=green]
                      >> function __construct($on e, $two="two", $three="three") {
                      >>
                      >> I cannot instantiate this object as new Foo($one, $three) since there is
                      >> no typing on the arguments and, therefore, no signature for a 'one,
                      >> three' contructor.[/color]
                      >
                      > Imho that's the same as saying: I'm standing with my back against a wall,
                      > and now i'm wondering why i can't step backwards anymore...
                      >
                      > Define your constructor as __constructor($ args) and handle with
                      > func_num_args and func_get_args(s ) any number of parameters...
                      >
                      > (I do agree that the language/compiler can, probably should, make this
                      > easier... But that's a different discussion.)[/color]

                      What you have specified is a non-overloaded generic constructor. I view
                      this as a work-around due to the inability of the PHP interpreter to
                      handle overloading polymorphism.

                      I'm not saying that this is a bad thing - in fact if you rewind your
                      news feed about a week - you will see that I recommended such an
                      approach to another coder, but I am saying that most strongly-typed OO
                      languages do support overloading as part of the their OOP environment.

                      -david-


                      Comment

                      • Jerry Stuckle

                        #26
                        Re: Object Oriented PHP

                        Tim Van Wassenhove wrote:[color=blue]
                        > On 2006-06-25, David Haynes <david.haynes2@ sympatico.ca> wrote:
                        >[color=green]
                        >>PHP5 has weak polymorphism but not true polymorphism in the sense that
                        >>it is used in OOP.[/color]
                        >
                        >
                        > So how would you define polymorphism? And what exactly are the
                        > differences between 'weak' and 'true' polymorphism?
                        >
                        > If i look at http://en.wikipedia.org/wiki/Polymor...ter_science%29
                        >
                        > "The concept of polymorphism applies to data types in addition to
                        > functions. A function that can evaluate to and be applied to values of
                        > different types is known as a polymorphic function. A data type that
                        > contains elements of different types is known as a polymorphic data
                        > type."
                        >
                        >[color=green]
                        >>function __construct($on e, $two="two", $three="three") {
                        >>
                        >>I cannot instantiate this object as new Foo($one, $three) since there is
                        >>no typing on the arguments and, therefore, no signature for a 'one,
                        >>three' contructor.[/color]
                        >
                        >
                        > Imho that's the same as saying: I'm standing with my back against a wall,
                        > and now i'm wondering why i can't step backwards anymore...
                        >
                        > Define your constructor as __constructor($ args) and handle with
                        > func_num_args and func_get_args(s ) any number of parameters...
                        >
                        > (I do agree that the language/compiler can, probably should, make this
                        > easier... But that's a different discussion.)
                        >[/color]

                        The constructor overloading example isn't really polymorphism. It's just
                        function overloading.

                        Polymorphism is the ability to operate on objects of derived classes, without
                        knowing what the derived classes are (or potentially even the existence of the
                        derived classes).

                        For instance - let's say we have class "mammal" with function "eats". Now all
                        mammals eat something, but what the class of mammals eats is not defines.

                        So, derive from mammal the class "ape" and have eats return "bananas". Also
                        derive the class "horse" and have eats return "oats".

                        Now - when you create an object of the class "ape" you can pass it to a function
                        which takes a "mammal". And you can print out what *this* mammal eats. The
                        same with a horse.

                        Polymorphism is closely tied to inheritance. But while inheritance allows the
                        programmer to take advantage of the commonalities between classes, polymorphism
                        allows the program to take advantage of the differences.


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

                        Comment

                        • Tony Marston

                          #27
                          Re: Object Oriented PHP


                          "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                          news:l7mdnYQJ5O PlEwPZnZ2dnUVZ_ q-dnZ2d@comcast.c om...[color=blue]
                          > Tony Marston wrote:[color=green]
                          >> "David Haynes" <david.haynes2@ sympatico.ca> wrote in message
                          >> news:Tvkng.2253 7$oG2.21662@fe2 6.usenetserver. com...
                          >>[color=darkred]
                          >>>Tony Marston wrote:
                          >>>
                          >>>>"Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                          >>>>
                          >>>>>Actually , things like private declarations are very important. They
                          >>>>>are unimportant only to those who don't understand OO programming - or
                          >>>>>those who are sloppy in their implementations .
                          >>>>
                          >>>>You don't *need* private declarations. Code will work just as well
                          >>>>without them.
                          >>>>
                          >>>
                          >>>What the heck! Let's just throw away multiply and divide. We don't *need*
                          >>>them. We can just use add and subtract.
                          >>>
                          >>>Heck! Why do we need subtract? We can just add negative values.
                          >>>
                          >>>Hey! Assembler works well without private declarations. Let's just pitch
                          >>>PHP all together.
                          >>>
                          >>>The point is that constructs are added to language to assist in the
                          >>>functionalit y and maintainability of programs written in that language.
                          >>>The introduction of private and protected adds to the maintainability
                          >>>both through its inherent protection capabilities and its clarity of
                          >>>intent for the maintainer.
                          >>>
                          >>>Now if PHP could just get polymorphism...[/color]
                          >>
                          >>
                          >> OOP with PHP already has polymorphism. You obviously don't know what
                          >> polymorphism means.
                          >>[/color]
                          >
                          > No, Tony, you really don't know what polymorphism is, do you?[/color]

                          The simplest definition of polymorphism is "same interface, different
                          implementation" . This means that different objects can share the same
                          interface but which do different things. What do you think it means?

                          --
                          Tony Marston

                          This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

                          RADICORE is a Rapid Application Development Toolkit for building Administrative Web Applications which are platform independent, browser independent and database independent.




                          Comment

                          • Tony Marston

                            #28
                            Re: Object Oriented PHP


                            "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                            news:l7mdnYUJ5O PIEwPZnZ2dnUVZ_ q-dnZ2d@comcast.c om...[color=blue]
                            > Tony Marston wrote:[color=green]
                            >> "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                            >> news:4K2dnSM18o D9YQDZnZ2dnUVZ_ oWdnZ2d@comcast .com...
                            >>[color=darkred]
                            >>>David Haynes wrote:
                            >>>
                            >>>>Jerry Stuckle wrote:
                            >>>>[/color]
                            >>
                            >> < snip >
                            >>[color=darkred]
                            >>>I really don't know how hard it would be to add - but I would like to see
                            >>>it added. One thing I don't like all that much is the untyped variables.
                            >>>It makes things "easy" - but leads to some sloppy programming.
                            >>>
                            >>>It also means you can't overload functions - at least not with the same
                            >>>number of parms. Typing the constructor arguments is a good start. But
                            >>>expanding that to other functions without breaking existing code might be
                            >>>more difficult.[/color]
                            >>
                            >>
                            >> You don't need function overloading in PHP. Why? First you need to look
                            >> at why other languages need it:
                            >> (a) To accept arguments of different types.
                            >> (b) To make some arguments optional.
                            >>
                            >> With PHP you can accept an argument of any type and then cast it to the
                            >> one you want, so item (a) is irrelevant.
                            >>
                            >> With PHP you can define a default value for an argument if it is not
                            >> supplied, so item (b) is irrelevant.
                            >>[/color]
                            >
                            > Sure. I would love to be able to have a function which does different
                            > things based on the type of parameter passed. It would save a lot of work
                            > trying to sort out parameters and potentially having to change existing
                            > code when adding new parameter types.
                            >
                            > But we already know you don't understand or appreciate real OO
                            > programming, Tony. So quite frankly, I don't give a damn what you think.[/color]

                            Just because my understanding and implementation of OOP is different from
                            yours does not make you right and me wrong.

                            --
                            Tony Marston

                            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

                            RADICORE is a Rapid Application Development Toolkit for building Administrative Web Applications which are platform independent, browser independent and database independent.




                            Comment

                            • Tony Marston

                              #29
                              Re: Object Oriented PHP


                              "Tim Van Wassenhove" <timvw@users.so urceforge.net> wrote in message
                              news:e7ltu2$cjc $1@ikaria.belne t.be...[color=blue]
                              > On 2006-06-25, David Haynes <david.haynes2@ sympatico.ca> wrote:[color=green]
                              >> PHP5 has weak polymorphism but not true polymorphism in the sense that
                              >> it is used in OOP.[/color]
                              >
                              > So how would you define polymorphism? And what exactly are the
                              > differences between 'weak' and 'true' polymorphism?
                              >
                              > If i look at
                              > http://en.wikipedia.org/wiki/Polymor...ter_science%29
                              >
                              > "The concept of polymorphism applies to data types in addition to
                              > functions. A function that can evaluate to and be applied to values of
                              > different types is known as a polymorphic function.[/color]

                              Exactly! Same interface, different implementation.

                              --
                              Tony Marston

                              This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

                              RADICORE is a Rapid Application Development Toolkit for building Administrative Web Applications which are platform independent, browser independent and database independent.




                              Comment

                              • Tony Marston

                                #30
                                Re: Object Oriented PHP


                                "David Haynes" <david.haynes2@ sympatico.ca> wrote in message
                                news:pRsng.2258 5$ax6.3306@fe43 .usenetserver.c om...[color=blue]
                                > Tony Marston wrote:[color=green]
                                >> "David Haynes" <david.haynes2@ sympatico.ca> wrote in message
                                >> news:Tvkng.2253 7$oG2.21662@fe2 6.usenetserver. com...[color=darkred]
                                >>> Tony Marston wrote:
                                >>>> "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
                                >>>>> Actually, things like private declarations are very important. They
                                >>>>> are unimportant only to those who don't understand OO programming - or
                                >>>>> those who are sloppy in their implementations .
                                >>>> You don't *need* private declarations. Code will work just as well
                                >>>> without them.
                                >>>>
                                >>> What the heck! Let's just throw away multiply and divide. We don't
                                >>> *need* them. We can just use add and subtract.
                                >>>
                                >>> Heck! Why do we need subtract? We can just add negative values.
                                >>>
                                >>> Hey! Assembler works well without private declarations. Let's just pitch
                                >>> PHP all together.
                                >>>
                                >>> The point is that constructs are added to language to assist in the
                                >>> functionality and maintainability of programs written in that language.
                                >>> The introduction of private and protected adds to the maintainability
                                >>> both through its inherent protection capabilities and its clarity of
                                >>> intent for the maintainer.
                                >>>
                                >>> Now if PHP could just get polymorphism...[/color]
                                >>
                                >> OOP with PHP already has polymorphism. You obviously don't know what
                                >> polymorphism means.
                                >>[/color]
                                > Tony:
                                >
                                > PHP5 has weak polymorphism but not true polymorphism in the sense that it
                                > is used in OOP.
                                >
                                > You cannot, for instance, have multiple constructors for an object where
                                > the number of the arguments to the constructor are variable. Yes, you may
                                > supply default values to 'optional' arguments but consider this example:
                                >
                                > class Foo {
                                > function __construct($on e, $two="two", $three="three") {
                                >
                                > I cannot instantiate this object as new Foo($one, $three) since there is
                                > no typing on the arguments and, therefore, no signature for a 'one, three'
                                > contructor. Nor could I define multiple __constructor() methods to allow
                                > for the new Foo($one, $three) case.[/color]

                                Polymorphism means "same interface, different implementation" . It has
                                nothing to do with overloading.
                                [color=blue]
                                > This type of action is common in other OOP languages such as Java and C++.[/color]

                                Just because those languages have to employ a certain mechanism to achieve a
                                certain result does not mean that EVERY language has to employ the same
                                mechanism to achieve the same result. Different languages work differently,
                                so you should expect different languages to achieve similar results with
                                different techniques. If everything was the same there would be no need for
                                different languages, would there?
                                [color=blue]
                                > To add to the confusion from an OOP programmer's viewpoint, in order to
                                > invoke the 'default' value for $three, I *must* supply a value for $two.
                                > That is, new Foo($one, , $three) is syntactically illegal and there is
                                > AFAIK no way to specify that we want $two to take its default value while
                                > supplying a value for $three.
                                >
                                > So, maybe its not me who is unclear on the concept of polymorphism...[/color]

                                I repeat, overloading has nothing to do with polymorphism.

                                --
                                Tony Marston

                                This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

                                RADICORE is a Rapid Application Development Toolkit for building Administrative Web Applications which are platform independent, browser independent and database independent.




                                Comment

                                Working...