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 #185130 is a reply to message #185125] Thu, 27 February 2014 21:14 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 2/27/2014 12:29 PM, Thomas 'PointedEars' Lahn wrote:
> 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 :->
>

Which does not contradict my statement.

>> 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.
>

Yes, and in real OO languages, it uses a constructor to do so. It does
not eliminate the need for the constructor(s).

For instance, a factory object cannot directly initialize the private or
protected members of an object (an exception being if it is declared a
"friend" object in C++ - which is frowned upon), nor can it initialize
the private or protected members of a base class.

But then a factory is generally not a static method of an object; rather
it is normally another object.

>> It does not replace or preclude the constructor being called.
>
> Nobody said it would.
>
>> [tl;dr Jerry's further misconceptions]
>
>
> PointedEars
>

Shot down again, Pointed Head.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
[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: Sun Nov 24 01:01:01 GMT 2024

Total time taken to generate the page: 0.05345 seconds