The classic example of a place where something like this is needed is in a comparison method. Frequently, a comparison between two instances of a class requires data that should remain private to the instances, but because of the private scoping rules, it becomes necessary to expose that data as part of the object's interface. Allowing the method to be declared private, but accessible from another instance allows those sorts of internal details to remain hidden.
The situation where I ran into this was looking into adding time zone support to the DateTime class. The init method is horribly overloaded...to the extent it would be difficult to add an additional timezone parameter to the method. A simple solution would be to add a method that will adjust the timezone bit after the object is constructed. This would be used by the various class fromXxxxx methods that create DateTime instances. Adding a timezone argument to those is a much simpler task because these methods don't use method overloading. Unfortunately, DateTime objects are supposed to be immutable, and currently, the only way to add a method that can be called from the class object is to make it public scope. But making this public scope means DateTime objects can be altered by anybody because there are no access restrictions on this method. I'm also fine with making this a new scoping level and leaving PRIVATE alone. The ideal name would be PROTECTED, since that has parallels in other languages. That name is taken, so we'd need a new name. FAMILY might not be a bad choice. Rick On Thu, Aug 14, 2008 at 1:02 AM, Sahananda (Jon) Wolfers <[EMAIL PROTECTED]> wrote: >> Useful for specialized class methods that >> create instances (such as the "fromXxxxxx" methods on DateTime). > > I could do with an example of how/when you would use it & the benefit > derived please. > I cant imagine it. > I also vaguely wonder whether we need a third kind of scope between > 'private' and 'public' - sort of private-ish or family or authorised > personnel only > > thanks, > > Jon > > 2008/8/14 Mark Miesfeld <[EMAIL PROTECTED]> >> >> Rick, >> >> This is such a change that I think we need to discuss it for a little >> while. >> >> At first reading, I don't see a problem with it. >> >> I also have missed at times in the past the Java-like behavior, which >> I was used to when I first was working with ooRexx. But now I haven't >> done any serious thing with Java for years and I don't think I have >> missed it as much lately. <grin> >> >> It would be good to get some other people's perspective on this. >> >> -- >> Mark Miesfeld >> >> On Wed, Aug 13, 2008 at 4:33 PM, Rick McGuire <[EMAIL PROTECTED]> >> wrote: >> > There's one feature of other languages like C++ and Java I really miss >> > in ooRexx. In Java, an instance of a class can access non-public >> > methods and fields of another instance of the same class. ooRexx has >> > PRIVATE methods, but access to those methods is limited to calls from >> > the within the same object (via a call to self~whatever). If two >> > instances of a class need to share data, there's no protected way to >> > do this. It's necessary to define things with publlic access, and you >> > then need to trust that nobody will misuse the access. >> > >> > I have a simple proposal (and code...a surprisingly small amount of >> > code) for expanding the usable scope of PRIVATE methods: >> > >> > A PRIVATE method can be invoked from any of the following situations: >> > >> > 1) The caller is a method of the same object as the target (i.e., >> > invoked via self~whatever). This is the same as today. >> > 2) The caller is an instance of the same class that defined the >> > target method (the method's scope). This will allow an instance of a >> > class invoke a private method of another instance of the same class. >> > 3) The caller is a class object that is compatible with the scope of >> > the method. This allows class objects to also access private methods >> > of its own instances. Useful for specialized class methods that >> > create instances (such as the "fromXxxxxx" methods on DateTime). >> > >> > I have the code written for this, but because it's such a change in >> > behavior, I thought this should get some discussion on the list first. >> > >> > Rick >> > >> > >> > ------------------------------------------------------------------------- >> > This SF.Net email is sponsored by the Moblin Your Move Developer's >> > challenge >> > Build the coolest Linux based applications with Moblin SDK & win great >> > prizes >> > Grand prize is a trip for two to an Open Source event anywhere in the >> > world >> > http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> > _______________________________________________ >> > Oorexx-devel mailing list >> > Oorexx-devel@lists.sourceforge.net >> > https://lists.sourceforge.net/lists/listinfo/oorexx-devel >> > >> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> Oorexx-devel mailing list >> Oorexx-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/oorexx-devel > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Oorexx-devel mailing list > Oorexx-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/oorexx-devel > > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Oorexx-devel mailing list Oorexx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/oorexx-devel