super constructors: I can't take it anymore!
Regan Heath
regan at netwin.co.nz
Wed Aug 16 06:02:56 PDT 2006
On Wed, 16 Aug 2006 15:15:49 +0300, Serg Kovrov <kovrov at no.spam> wrote:
> * Oskar Linde:
>> Or, you can reconsider your design. One option is to make a register()
>> method that only the BaseWindow constructor calls. In you child
>> classes, you can overload the register() method anyway you wish.
>
> Yes, I thought about reconsider design to workaround this issue, but I
> can't find clean solution yet.
>
> Let me clear my design. Obvious hierarchy - a base class for common
> any-window functionality, and subclasses for common window cases (such
> top frame, button, reac hedit, etc) which may have more narrow but still
> generic, and finally end-user-classes for particular application.
>
> All windows classes must register (once) os class with its window
> procedure, and create a os window *when instancing*. That is one thing I
> do not want to change. e.g, when I do `new Button("push me")` I have
> button object ready for action. no need/worry to init it, it should be
> inited in constructor.
>
> Ok, next. I want unique window procedure for each 'generic' window
> class. eg BaseWindow FrameWindow, Probably I need to explain more, but
> do not want to bloat this message. In few words it is for performance
> reasons. And that approach I'd like to keep too.
>
> My original idea was - each of constructors call register() and create()
> methods with different parameters - window procedure callback and window
> classname.
How's this?
import std.stdio;
typedef int function(int i) WNDPROC;
class BaseWindow
{
void register(char[] cname) { writefln("register(",cname,")"); }
void create(int function(int) f) { writefln("create(",f(1),")"); }
char[] classname() { return "BaseWindow"; }
WNDPROC windproc() { return cast(WNDPROC)function int(int i){return i;}; }
this() { register(classname()); create(windproc()); }
}
class FrameWindow : BaseWindow
{
override char[] classname() { return "FrameWindow"; }
override WNDPROC windproc() { return cast(WNDPROC)function int(int
i){return i*2;}; }
}
void main()
{
FrameWindow b = new FrameWindow();
BaseWindow a = new BaseWindow();
}
Regan
More information about the Digitalmars-d-learn
mailing list