You are here: Re: PHP5 Singlton vs. Abstract Classes « PHP Language « IT news, forums, messages
Re: PHP5 Singlton vs. Abstract Classes

Posted by Jerry Stuckle on 11/21/72 11:30

Dikkie Dik wrote:
> Daedalus.OS wrote:
>
>
>
> The PHP help does not say anything about private constructors. I guess
> it is a java thing to make them private to disallow instantiation. If
> you think about it, it is quite odd. The constructor is never called
> directly, but it is a language construction. You give a "new" keyword,
> some space in memory is reserved, the class name is attached to it as a
> type, and its constructor is called. By whom? By the virtual machine
> itself, basically. Making it private is _really_ odd. As the object is
> still unreferenced, _no_ object can call it (the reference is only
> returned when the constructor has finished). Even the object itself
> cannot call it, as it is still in the process of coming to existence.
> It is not very consequent either. "private" in java means "visible only
> within the same instance". Only for constructors it suddenly means
> "visible within the same class".
> Declaring it abstract will certainly stop instantiation. However,
> "abstract", communicates that it is meant as a superclass. I would not
> create a constructor at all and not declare it abstract either. As the
> static operator differs from the normal method calling, it is clear
> enough that instantiation is pointless. Any instance does not have
> properties or methods that can be called on it.
>

Actually, it's not uncommon to have *some* constructors be private. If
all of them are private, you can only instantiate the class through a
static function.

But for instance - it's not unusual in C++ to have a copy constructor be
private. It means the following code will fail:

MyClass a; // Default constructor
MyClass b = a; // Copy constructor - fails if it is private



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

 

Navigation:

[Reply to this 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

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