Andre Poenitz wrote:

> On Thu, Mar 06, 2003 at 02:44:10PM +0000, Angus Leeming wrote:
>> // Lazy instatiation. Only build the thing when a particular
>> // dialog is requested.
>> Dialog * Dialogs::build(string const & name) {
>>         if (!isValid(name))
>>                 return 0;
>> 
>>         Dialog * dialog = new Dialog;
>>         if (name == "citation") {
>>                 dialog.setController(new ControlCitation(*dialog));
>>                 dialog.setView(new FormView(*dialog));
> 
> But that's dynamic. 

Sorry. That should be:
                dialog.setView(new FormCitation(*dialog));

> If you want that, you can't use the
> ControlCitation type in the ViewCitation clas...
> 
> This way a certain view can be coupled with any controler, so it
> can't possibly know the controler type at compile time.

Sure I can. However it requires that I write sane code. I could write
        if (name == "citation") {
                dialog.setController(new ControlCitation(*dialog));
                dialog.setView(new FormTabular(*dialog));
        }

which will compile fine. However FormTabular expects to see
        ControlTabular & controller() {
                dynamic_cast<ControlTabular&>(dialog().controller());
        }
which fails at run time because the dialog actually has a 
ControlCitation controller.

-- 
Angus

Reply via email to