My design need friends
Namespace
rswhite4 at googlemail.com
Sat Oct 5 12:06:48 PDT 2013
Hello. I hope one of you has a good idea to solve my design
problem.
I have 3 files in two different sub packages.
Package Bar has the interface Drawable:
----
module Bar.Drawable;
interface Drawable {
protected:
void _render();
package:
final void render() {
this._render();
}
}
----
and, for example, the class Graphic:
----
module Bar.Graphic;
import std.stdio;
import Bar.Drawable;
class Graphic : Drawable {
protected:
override void _render() const {
writeln("Graphics.render");
}
}
----
Package Foo has the class Window:
----
module Foo.Window;
import std.stdio;
import Bar.Drawable;
class Window {
public:
void draw(Drawable d) {
writeln("Window.draw");
d.render(); /// Error: interface Bar.Drawable.Drawable member
render is not accessible
}
}
----
As you can see, I try to access the render method from drawable.
But since Drawable is in another sub package, I have no access.
That is a situation where I liked to have 'friends' like in C++.
I have two solutions:
1. Move Window from package Foo to the package Bar. But that's a
ugly solution and I don't want to have any Window components in
my Bar package.
2. Make 'render' public instead package. That is my current
workaround. But I don't like it much since each other could also
access 'render', not only Window.
My question is: is there any other possible solutions? Any D
magic?
Thanks in advance.
More information about the Digitalmars-d-learn
mailing list