I’m stumped. I have a situation where in my web app, I have two different container controls that are nearly identical. They are like this because one container is used for Mobile devices, the other for desktop devices. In most respects their code base is identical but they have a couple of different controls and events. So I’ve created a class interface (called TVContainerInterface) with all the common methods used between the two containers. In my main code, whenever I do anything with any of these containers I always store and use the TVContainerInterface type because then I don’t really care which I am working with. So this is good because then I completely have abstracted exactly which type of container I am working with so all my code elsewhere in the app doesn’t really change.
That’s all great and it works good.
Except, I have to keep and maintain multiple sets of code that is in many cases identical. I wish I could create a class interface and have code added to the methods already in the interface - but I can’t.
I’ve thought about adding a class containing all the methods to the containers and skipping the interface, but then I lose the type the interface creates.
Would a module be a better thing where I keep all the common code in a module and call the module methods from the interface methods?
That is the most portable. Done in New Framework, it will work the same in the two platforms. The only issue I see is using on one hand iOSContainerControl based on Canvas and on the other hand ContainerControl based on EmbeddedWindows, so passing the container as argument may need to use extra work.
Well, the same issue presents : you may need to pass self as a window, containerControl, WebPage or WebContainer to your common methods. In Desktop and Web, you may need to use Variant and get the type to know what to do with what was passed.
Apart from that, I see no real problem using the same module or class in both environment.
Although they are ultimately different, big chunks of RubberViews and RuberViewsWE have simply been reused.
The hard part is that there’s similarity between both but enough differences that makes abstracting it a challenge. Some code is identical and that could be moved to a class no problem. Other code is nearly identical but maybe one or two lines different because the controls are different between the two containers. That’s where I have the trouble. You have 30 lines of code in an event or method and two lines are different. I suppose inside the class methods you could use the IsA function to determine which control I am dealing with and act accordingly.