cast(public)

Onassis Empederado OEmpederado at gmail.com
Fri Jul 17 20:29:42 PDT 2009


Nick Sabalausky Wrote:

> "dsimcha" <dsimcha at yahoo.com> wrote in message 
> news:h3q5td$2jqa$1 at digitalmars.com...
> >I know I've probably mentioned this one here before, but it was buried in 
> >long
> > threads.
> >
> > Could we put a feature in the language that allows private member 
> > variables to
> > be cast to public?  The idea is that, if a class/struct designer makes
> > something private, they're saying it's a bad idea to mess with it, and 
> > that
> > you do so at your own risk.  However, I think there needs to be a back 
> > door to
> > cowboy this one, because otherwise private/protected is just too 
> > restrictive
> > for a language like D.  It would work something like this:
> >
> > struct Foo {
> >    private uint bar;
> > }
> >
> > void main() {
> >    Foo foo;
> >    foo.bar++;  // error
> >    (cast(public) foo.bar)++;  // Works.
> > }
> 
> I don't see a real legitimate point to this. If you need something from a 
> module not provided by a public interface (or protected sub-classing) than 
> that needs to be properly added to the module's interface. Otherwise you're 
> just asking for your code to be broken (in a way that may *or* may not be 
> fixable) the moment the module you're hacking into is updated. Why hack it, 
> when you could just make a proper added feature? Sure, there may be 
> source-not-available stuff, but if you need some extra feature from a 
> library that doesn't have source available, and the lib's developers aren't 
> receptive to your need, then you're just simply using the wrong library 
> anyway.
> 
> 
It depends on the type of interface classes (implementation versus user-level interface using concrete/abstract types), where derived class can be created from it, considering with some levels of abstraction...by design.

Just my 2 cents.



More information about the Digitalmars-d mailing list