Design question

Hi all…

I’ve developed a lot of custom controls for our project. To speed things up, I am going to develop each control in its own Xojo project file.

However, each control depends on a class called AppLayout. The AppLayout class contains a color scheme which is applied to various coloring properties of the control.

I want to be able to have a project file with each control, without the AppLayout class and it’s dependencies. Therefore, I was thinking about changing the approach a bit by:

  1. Exposing the coloring properties for each control.
  2. Letting AppLayout catch Initializing event for each control and apply the color values.

My question… how would you guys implement this, theoretically speaking?

I was looking into polymorphism / inheritance but Xojo can be limited here.
https://documentation.xojo.com/getting_started/object-oriented_programming/oop_design_concepts.html

I hope the issue is clear enough.

I’m not sure it’s a good idea to have each control in its own project file (I assume by “project file” you mean a Xojo project, i.e. a program).

I’ve developed a bunch of custom controls. They are typically based on the Xojo controls, but they all implement a common interface. I keep them in a folder in the project I’m working on (along with the interface).

1 Like

Flip your dependency around. Have your controls stand alone, without requiring the AppLayout class. Instead, have each one raise an event asking for the color scheme upon initialization. The following event definition will live in your control base classes and is raised when the control is being set up:

Event InitializeColors() As boolean
   // ...do any necessary color setup here and return True
End

Then, you can have subclasses of your controls that do rely on AppLayout and implement the event:

Function InitializeColors() Handles InitializeColors() as boolean
    me.LineColor=AppLayout.DefaultLineColor
    me.TextColor=AppLayout.DefaultTextColor

    Return True
End Function

Dividing the code like this lets you reuse the control base classes in a project where you don’t want to loop in the AppLayout code.

2 Likes