Hello Moriyoshi,

Thursday, July 3, 2003, 6:50:46 PM, you wrote:

MK> [EMAIL PROTECTED] (Marcus Börger) wrote:

>> Not really. An interface simply describes a protocol subset that must be part
>> of the implementing class's protocol. In that it makes no sense to allow final
>> or private methods in an interface but still a protected member in an interface
>> would describe a subset of a protocol. And hence it would describe a method
>> that must be available with protected or public visibility. Or in other words
>> it would make it possible to hide a method per default from outside.
>> 
>> "A derived class must implement it but other classes are not supposed to use
>> it"
>> 
>> I came across this when i experimened with __clone.

MK> I don't know what you experienced with __clone exactly, but maybe you 
MK> wanted the class to allow accesses only from instances that have the same 
MK> interface as the one being invoked. If so, my suggestion is to let those 
MK> methods take a parameter that holds a caller instance and filter the 
MK> accesses to it by the condition applying "instanceof" operator to that 
MK> instance.

MK> p.s. A predefined variable like "$that" which indicates the caller 
MK> instance would be what you want?

Nice idea, but one thing i wanted is to disable cloning of class objects.

The following class makes cloning impossible for all derived classes:
class no_clone {
  final private __clone() {}
}

but the all classes that should not be cloned must be descendants from that
class. So the following interface would disallow cloning by default, although
it allows derived classes to reenable cloning:
interface no_clone {
  protected function __clone()
}

When dealing with classes that handle resources such techniques are very
helpful to prevent users from shooting themselves in the knee.


Best regards,
 Marcus                            mailto:[EMAIL PROTECTED]


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to