The error is “Parameter “view” expects interface IDatabaseExplorerView , but this class is a Window”
I am trying to implement MVP design pattern. A window I am designing inherits an interface. I have a Presenter class that takes the window(“view”) as a parameter as the interface type so the Presenter can call those methods of the interface on the window.
I’m able to do this in C# but how can I implement in XOJO?
Add a new Class to the project. Set its Super to Window. Add your interface to the list of interfaces the new class implements. Change the Super of your window to your new class name.
[quote=388288:@Chad Posner]The error is “Parameter “view” expects interface IDatabaseExplorerView , but this class is a Window”
I am trying to implement MVP design pattern. A window I am designing inherits an interface. I have a Presenter class that takes the window(“view”) as a parameter as the interface type so the Presenter can call those methods of the interface on the window.
I’m able to do this in C# but how can I implement in XOJO?[/quote]
Inherits an interface ? Or implements an interface?
What Tim said will work and another option is to open the inspector for the Window and add the interface to the list of interfaces the Window implements.
Well, now it seems to be working as expected. I just created a new window, implemented my interface(copied and pasted all my controls and code) and now I can pass it into my constructor. I wonder if I can reproduce the error.
Window1 implements the IDatabaseExplorerView interface directly. Button1 instantiates a new Presenter object and passes it Window1. It compiles without errors.
Anyway, I agree with Tim. In doing that you are losing the advantage of the pattern you’re implementing.
Javier[/quote]
Thanks for the link. I was actually looking for Casting in the help docs(I didn’t find it) for some other things and I’m glad I don’t need it for this case.
[quote=388411:@Chad Posner]When doing the following:
Create New Class -> Set It’s Super To “Window” The actual “window” object where I can place controls does not exist.[/quote]
Thats the intended behavior. You are creating a subclass of Window, not an instance of it. An instance is the only place you can use the layout editor. Youd have to add controls programmatically otherwise, probably during the open event handler. Which means youd have to use AddHandler calls for every control you created this way. A lot of work!
(There are exceptions to the rule above like ContainerControls)
So what you did is perfectly fine: Create a Window and set its super to your new subclass, but use the layout editor for the design. If you reuse a certain window design with slight modifications, create a template and copy it for every window instance of this kind.
If you are unsure about the final template design, use a ContainerControl for the windows general content so you wont have to redesign every instance you already created.
When you create a class whose Super is Window, it is code-only. You cannot subclass layout. But when you go to a normal window and change its Super to your window subclass, it inherits all the code from that class. That allows you to have a group of windows that all have the same functionality built in.