t-oster / VisiCut

A userfriendly tool to prepare, save and send Jobs to Lasercutters
https://visicut.org
Other
235 stars 115 forks source link

Introduce Null Object pattern #714

Open TheAssassin opened 8 months ago

TheAssassin commented 8 months ago

There are various locations within the code where a == null check is needed. For instance, when querying the bed width or originBottomLeft properties, default values need to be used if no device has been selected most of the time.

The Null Object pattern fills such attributes with sensible "default" values. For instance, a null LaserDevice might have a bed width of 600mm, a bed height of 300mm and a top left origin. This would replace the many duplicate default values scattered across the whole code base.

There might be other use cases as well. I'll first add it to LaserDevice in preparation for my work on #713.

TheAssassin commented 8 months ago

I've worked with the codebase for a few days now and given the number of occurrences and the less-than-ideal interface design (many interfaces are quite bloated), I've come to the conclusion that this pattern won't solve any actual problems, at least for now. Some refactoring is required beforehand, namely reorganizing LaserDevice and LaserCutter and related classes. I'll continue with the existing codebase for now, #713 is a bigger priority.