Mapping properties in separate hierarchies
If you observed the starter project closely, you may have noticed that MovementController.cs
and TeleportController.cs
both have a property called moveSpeed
. However, if we wanted our client to reference this in some way, we couldn’t make that happen as-is because the moveSpeed
property isn’t present in their shared interface – which is exactly what we’re going to fix in this section.
I’m using this super-simple contrived scenario to showcase how the Adapter pattern could be used to consolidate incompatible class properties, but it’s important to think about where this could benefit your codebase. Are there built-in classes that you wish shared a parent class? Are there classes that share a parent class but that parent is so far up the class hierarchy that the property you want to access isn’t present? Are there classes for each of these situations that you can’t modify for...