Be API constructor duties

I’m looking at the API for Ocaml, which has a strongly typed OOP, and there’s a kind of chicken/egg problem with the two OOP systems put together - the C++ object needs the Ocaml callbacks for the hook virtual functions that the class will provide, and the class needs the object in order to be constructed. I might be able to figure out some other way around this if necessary, but at the moment I seem to be able to make it work by simply doing the `derived class’ initialization, from Ocaml, after the object has returned from the constructor.

So B_my_wrapper_Window(…): BWindow(…) { } // i.e., the C++ classes never do anything beyond their constructors from the factory, and custom view children etc. all are added at a later time. Well, immediately later.

Am I missing some common case where derived classes need to work something out before the constructor returns? So far I’ve only OOP-ified BWindow.

With the non-OOP side of Ocaml I can call back to an initialization function - that works OK.

I’m confused :face_with_spiral_eyes:. Maybe it would help if you wrote a more in-depth explanation of what you’re trying to do. I have experience with writing Python API bindings, so, I might know the solution to the chicken and egg problem that you’re encountering, but I’m not exactly sure what the chicken and egg problem is.

Maybe? I can’t think of any, so, perhaps it’s not that common. But, in the end, I haven’t done that much extending of Be API classes, so, I don’t really know.

That’s the question, so thanks for that.

I have experience with writing Python API bindings myself, as it happens, and as I mentioned the Ocaml bindings are OK up to a point. For a start on understanding the problem, look up “strong typing”, but anyway it all gets simpler if I don’t have to put callbacks into the constructor.

I can’t think of a problem with what you did. Usually I end up having to move code out of the constructoreand into ReadyToRun or AttachedToWindow or the like, but rarely in the other direction.

The looper won’t do anything until you Run theme the views until you attach them to a window, the windows until you Show them. Eâerything before that is “initialization” and it doesn’t matter if it’s in the constructor or not.

1 Like