Object Casting in Mendix from Special Forces’ Perspective
Did you know that Special Forces use 360° sensors as part of their operations to deal with all unforeseen events and enemies? Sensors are a world reference for the Special Forces’ ability to rapidly detect threats. For now, let’s focus on the enemy.
When an enemy has been detected, the individuals of the Special Forces need to know what type of enemy it is. The fact that it is an enemy is too broad, and the unit needs to know the specific details of the enemy. The enemy can be a person, a car, a jet, a tank, etc.
Besides that, in case there was a false alarm because there was no enemy, there should be a detailed report to the manufacturer of the sensor in order to respond to the wrong detection.
In Mendix, we call the process of converting a generalized object into a specialized entity: Object Casting. The generalization might cover the basic attributes of the specialization, but it takes the specialized attributes to describe the object to its fullest.
So, when a Special Forces unit detects an enemy tank, it will look for specific tank properties, like size of the vehicle or color of the steel. If the same unit detects an armed person, it will look for specific human properties, like uniform or type of weapon. It would be a waste of time to look for the color of steel when detecting an armed person. The same goes for looking for uniform details when an enemy tank has been detected.
To wrap this up, when you have a Mendix application and you need access to the specialized attributes of a generalization, use Object Casting. Object Casting uses a generalized object as input, and Mendix automatically detects the specialization and returns the specialized object as the output. Just like the detection sensors of the Special Forces unit detect whether the enemy is a tank or a foot soldier, Mendix Object Casting detects which specialized attributes the generalized object has.