On Thursday, 16 January 2014 at 09:28:18 UTC, Boyd wrote:
Hi there,
I have an idea for an access modifier that I wanted to throw
out there, in the hopes that it will resonate with someone.
Basically I've found that in practice, when building a module,
I always need to keep two kind of users in mind. Those who want
to use it, and those who want to extend it.
For extending, there is the 'protected' attribute, but it's
specific for class overriding only. Very often, extensions are
not merely limited to derived classes. What I find myself
wanting is more like the 'package' attribute, except it needs
to work outside of the package as well.
So right now, the only viable choice is making all
functionality for users and extenders 'public'.
So let's imagine the 'extendable' attribute for a moment.
Here's what I would like it to do:
Let's say someone built a GUI library, and without access to
the library, I want to add support for another platform.
------
module buttoncontrol
public class ButtonControl
{
public Event pressEvent;
extendable void click(Point position);
}
------
Now, you don't want a user to be able to generate a click. But
someone whose purpose it is to extend the library, should be
able to do it.
extender
------
import extendable buttoncontrol;
void click(Point position)
{
auto button = findButtonUnderCursor(position);
button.click(position);
}
------
user
------
import buttoncontrol;
void createUi()
{
auto button = new ButtonControl();
button.click(Point(10,10)); // ERROR, no access to click
function
}
------
So, that's the general idea. I haven't thought very hard about
the syntax part, so ignore that. Let me know what you think. Is
it useful? feasible? worth the effort?
Cheers,
Boyd
This can be achieved with traditional OOP design patterns and i
have to agree with the above poster this is too much like C++
hacking and looks horrible.