From my experience with other OOL it is generally a best practice to NOT use base classes directly, but to create your own subclasses for all base classes.
Is that recommended for Xojo as well?
If so, what is the most efficient method to create all of these subclasses?
I am very new to Xojo, so I apologize if this has been asked/answered already. I did do a Google search and a Google site search of the Forum, and a search of the Xojo documentation, but did NOT find an answer to this. A lot of other OOD: Classes info, but not how to subclass all base classes.
Thanks, Christian. That is what I want to do, but I’m looking for an automated way to subclass all base classes, rather than having to manually create a new subclass for each one.
Thanks, Karen. Yes, that is the primary reason to subclass. For example, I may want to use a different font size and font face for all of the relevant controls.
Not unless you need to customize it
And there are things that will give you grief
I’d suggest only subclassing when you need to do it and not as a general rule
OK, that sounds like a plan. I’d be surprised if someone had not already done this, and I’d expect subclassing is a very common use case. I’ll do some research on IDE scripting.
Well, I don’t know about “easier”.
I’d rather spend my time writing a script rather than having to set the properties each and every time I add a control to a window.
Thanks, Norman. Can you give me some examples? I’ve never experienced problems with subclassing, at least to only a few levels?
Does Xojo have a problem with subclassing?
I appreciate the caution, but could you please be specific?
[quote=491593:@Jim Underwood]Well, I don’t know about “easier”.
I’d rather spend my time writing a script rather than having to set the properties each and every time I add a control to a window.[/quote]
I think subclassing window and in the open event iterating over the controls in a generic way to set your defaults is easier than writing a xojo script! You would not be setting them manually that way either and you only need to create one subclass.
No … I think he me meant because properties are not virtual… you can only shadow properties, which can cause issues if you want to change the behaviors they affect.
-karen
It has “gotcha’s” that if you dont know about them they will bite you
And, because of some of these and how you have to deal with them you can accidentally introduce the fragile base class problem
Super. wont work so you cannot write
Super. = someValue
in your subclass
Note that the “right” way to do shadowing introduces the fragile base class problem as now your subclass MUST know its super since properties are not virtual
[quote=491580:@Jim Underwood]From my experience with other OOL it is generally a best practice to NOT use base classes directly, but to create your own subclasses for all base classes.
Is that recommended for Xojo as well?[/quote]
No. It is not. You should only subclass when you find a real need. Xojo classes are fully functional out of the box.
It isn’t a question of whether the base classes are fully functional, or not – I’m sure they are.
It is a question of ease of global customization later on, after the app is fully developed, and even deployed.
For example, how you guys handle this: Many clients want and expect the ability to change certain UI features like font face and font size, across the entire app. So how would you provide this without using subclasses?
For that matter, the base classes for Labels, TextFields, TextAreas, etc do not have a property shown in the IDE for font face.
How would you provide a consistent font across the entire app if you did not want to use the “system” font?
[quote=491658:@Jim Underwood]For that matter, the base classes for Labels, TextFields, TextAreas, etc do not have a property shown in the IDE for font face.
[/quote]
It would be easier to follow Karen’s suggestion and subclass Window and put code in it to set the attributes of all the controls on the window. That said, there are several controls that I have subclassed to add additional functionality. But not all controls need it. I put them in an external module so I can share them between projects. I have code in my window subclass to set typeface and size, and to dynamically resize all the controls to achieve an “elastic” feel to the window.