Class views - a new concept

forkit forkit at gmail.com
Sun Jun 26 23:33:42 UTC 2022


So I came up with this idea, based on discussion in another, 
rather controverial, thread ;-)

In any case, I think this idea deserves it's own thread.

NOTE::it's just an idea, and certainly **not** a proposal.

I'd be interested to know, if anyone else out there knows of any 
langauge, where a concept like this has been implemented (i.e. a 
way to restrict specific class member functions to specific class 
variables).

So...here I introduce a new concept, which (for now), we'll call 
a 'view'.

It can solve multiple problems, at least for me.

First, it eliminates a need for that very controversial idea of 
'private(this)'

Second, it allows fine grained control of member access, to 
member variables.

Anything declared private, in a view, is simply private to that 
view.

Destroy! (but try to be civil too)


class myClass
{
     @view
     {
         private:
           int x;

     	public:
           void setX(int x) { this.x = x; }
           int getX( return this.x; }
     }


     private:
       void fred() { this.x = -1; }  // error: fred is not part of 
the view that contains x
       int waldo() { return this.x; } // error: waldo is not part 
of the view that contains x

     public:
       void foo() { this.x = -1; }  // error: foo is not part of 
the view that contains x
       int bar() { return this.x; } // error: bar is not part of 
the view that contains x
}





More information about the Digitalmars-d mailing list