Reply to Re: Object Oriented PHP

Your name:

Reply:


Posted by Tony Marston on 06/25/06 13:54

"David Haynes" <david.haynes2@sympatico.ca> wrote in message
news:wawng.46054$dP1.24219@fe03.usenetserver.com...
> Tim Van Wassenhove wrote:
>> On 2006-06-25, David Haynes <david.haynes2@sympatico.ca> wrote:
>>> PHP5 has weak polymorphism but not true polymorphism in the sense that
>>> it is used in OOP.
>>
>> 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/Polymorphism_%28computer_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."
>
> 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)."
>
>>> function __construct($one, $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.
>>
>> 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.)
>
> 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.

Just because PHP does not handle overloading in the way that other languages
do does not mean that it does not support polymorphism. Overloading is not
the same as polymorphism. They are different concepts that may or may not be
employed at the same time.

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация