FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Operator precedence
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Object constructors/destructors [message #185125 is a reply to message #185117] Thu, 27 February 2014 17:29 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Jerry Stuckle wrote:

> On 2/26/2014 7:00 PM, Thomas 'PointedEars' Lahn wrote:
>> Christoph Michael Becker wrote:
>>> Jerry Stuckle wrote:
>>>> On 2/25/2014 6:22 PM, Adam Harvey wrote:
>>>> > On Tue, 25 Feb 2014 17:01:52 -0500, Jerry Stuckle wrote:
>>>> >> On 2/25/2014 4:55 PM, Christoph Michael Becker wrote:
>>>> >>> Jerry Stuckle wrote:
>>>> >>>> I know of no other OO language which would allow this.
>>>> >>> Others may.
>>>> >> None that I know of. Please name one.
>>>> >
>>>> > Python's pickle operates the same way:
>>>> > http://docs.python.org/2/library/pickle.html#object.__getinitargs__
>>>> >
>>>> > Providing a way to instantiate objects without calling the constructor
>>>> > does have valid uses (mostly for testing), which is why PHP 5.4 and
>>>> > later versions also provide a way to do so via reflection (avoiding
>>>> > the unserialize() hack):
>>>> > http://php.net/reflectionclass.newinstancewithoutconstructor
>>>>
>>>> Not knowing Python, I can't say. But if it is a true object, then they
>>>> are also violating OO principles.
>>>>
>>>> OO demands creation of a new object requires a constructor call.
>>>> Period.
>>>
>>> Do you understand, what's the purpose of a constructor? It is there to
>>> *initialize* an instance. If there is nothing to initialize, it is not
>>> strictly necessary to call any constructor.
>>
>> A constructor does not need to mean initialization; primarily it means
>> *instantiation*: creating an object and, optionally, creating a relation
>> between it and another object (in the general sense) it inherits from.
>> However, both instantiation and initialization also can be done by a
>> factory method. Factory is one of the GoF design patterns, and it does
>> not violate principles of OOP at all (those people *literally* wrote the
>> book on OOP). A factory is a function, usually (but not necessarily) a
>> static method, that returns (a reference to) an object.¹
>
> Incorrect (as usual). The constructor is designed to initialize an
> object. In OO programming, an object is always valid, or, if not valid,
> refuses any operations which depend on the object being valid.

At this point I would refer you to “Design Patterns. Elements of Reusable
Object-Oriented Software” (ISBN 3-8273-2199-9) if I not already knew that
you knew everything that is to know about OOP :->

> A factory is only a means of instantiating the object.

No, it can initialize the object, too. I have already given an example *in
PHP*; you are not paying attention.

> It does not replace or preclude the constructor being called.

Nobody said it would.

> [tl;dr Jerry's further misconceptions]


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Correlating curl resources to some other object.
Next Topic: Experienced Web designer required
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 23:55:37 GMT 2024

Total time taken to generate the page: 0.04073 seconds