Tuesday, February 10, 2015

Ruby: Dynamic Dispatch / Entrega Dinámica

Ruby language has not mutiple-polymorphism, so diverse techniques have been uesed to achieve the same result. Dynamic Dispatch is one of them, easily confuse with late binding, this technique let decide in run-time the implementation to call.
Let's say we have a class Docs with two sublasses Invoice and Order; these three classes have a method named Name. In a given code we can call Docs.Name and get a name, now with dynamic dispatch, if we call Docs.name the system will decide if we call this function from Docs, Invoice or Order class like could happen in an implementation where the run-time decide to call Order.Name because the argument given belong to the suppliers list and not to the customer list.