July 12, 2018
Default Function In Interface
Like
(0)
Comments
(1)
0
1
Default functions can be provided to an interface without affecting implementing components as it includes an implementation. If each added method in an interface is defined with implementation then no implementing component is affected. An implementing component can override the default implementation provided by the interface.
Imagine a scenario where you want to add a new function to a public interface, without default function, it would be a Herculean task since all consumers will need to provide an implementation. A default function is the solution, as the default implementation is provided in the interface; the consumers no longer need to provide an implementation.
In ColdFusion, you can declare a default function as follows:
interface { default Any function returnsAny(){ return "hello from I interface"; } void function acceptAny(string x); }