I’m working on the Linkage program and I am having trouble solving a problem; I have three classes that need bases classes to simplify their definitions and construction. The classes can be described as Control Knobs, Connectors, and Links. In the code itself, things like drawing elements are just connectors and links that are on the drawing layer and are drawn differently because of it. The common data is a set of coordinates for the control knobs and connectors and colors for the connectors and links. They can all be selected so that trait is shared with all three of them.

If I were writing this with Swift or C#, I would use a protocol or interface respectively. I’ve been writing a lot of Swift code lately so protocols in that language are very familiar to me. I would write a definition for a protocol that included X and Y coordinate properties (or a point property in most cases) and then use that protocol in the definition of the control knob and connector classes. Those classes would then also have the proper property or properties to meet the protocol definition. The cool part is that I would then write the code so that the methods or functions that just work with the coordinates of objects take a protocol as an argument or parameter. It’s a nice way to design things and would allow me to have the structure I need. What I need is to have the control knob class and connector class each be defined based on a “coordinate class” protocol and the connector and link classes would be defined based on a “color-able class” protocol.

C++ has no protocol features.

I’m stuck with multiple inheritance and I have never actually used it before! What I’m thinking of doing is adding an abstract class that has a “get coordinates” function and then using that for the base of the control knob and connector classes. When I need to act on the coordinates, like in the function that does snapping to elements while dragging elements, I can use the abstract base class as a parameter type.

I have no idea if this will work but I really don’t want to give coordinates to links as they have a width and height and their coordinates are sort of ambiguous or ill-defined.

Note that C# has interfaces which are used just like the Swift protocols. To be honest, the fact that I switch between three or four languages every week in my job makes it tough to remember what language features are called and how they work. Now on to writing that code…