Default Function In Interface

July 12, 2018
Newbie 4 posts
Followers: 1 people
1

Default Function In Interface

Newbie 4 posts
Followers: 1 people
July 12, 2018

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);
}

 

Comments (1)
2018-07-13 09:41:20
2018-07-13 09:41:20

“default Any function returnsAny(){”

shouldn’t that be something like

“default public Any function returnsAny(){

?

Or just do away with “default” and allow public/private in interface…

Like
Add your comment