function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VijoVijo 

implement an interface on interface

Is there a way to implement an interface on another interface, like say my custom interface that implements both the Database.batchable and Schedulable?
Best Answer chosen by Vijo
NagendraNagendra (Salesforce Developers) 
Hi Vijo,

implements mean implementation when an interface is meant to declare just to provide an interface, not for implementation. In other words, implements mean a behavior will be defined for abstract methods (except for abstract classes obviously), you define the implementation.
extends means that a behavior is inherited.

A 100% abstract class is functionally equivalent to an interface but it can also have an implementation if you wish (in this case it won't remain
100% abstract), so from the JVM's perspective they are different things.

Also, the member variable in a 100% abstract class can have any access qualifier, wherein an interface they are implicitly public static final.

With interfaces, it is possible to say that one interface should have that the same behavior as another, there is not even an actual implementation. That's why it makes more sense for an interface to extends another interface instead of implementing it.

In general, even though an interface is "a 100% abstract class," we don't think about them that way. We usually think about interfaces as a promise to implement certain key methods rather than a class to derive from. And so we tend to use different language for interfaces than for classes.

So finally the conclusion would be, an interface cannot implement another interface.

Hope this helps.

Kindly mark this as solved if my reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Vijo,

implements mean implementation when an interface is meant to declare just to provide an interface, not for implementation. In other words, implements mean a behavior will be defined for abstract methods (except for abstract classes obviously), you define the implementation.
extends means that a behavior is inherited.

A 100% abstract class is functionally equivalent to an interface but it can also have an implementation if you wish (in this case it won't remain
100% abstract), so from the JVM's perspective they are different things.

Also, the member variable in a 100% abstract class can have any access qualifier, wherein an interface they are implicitly public static final.

With interfaces, it is possible to say that one interface should have that the same behavior as another, there is not even an actual implementation. That's why it makes more sense for an interface to extends another interface instead of implementing it.

In general, even though an interface is "a 100% abstract class," we don't think about them that way. We usually think about interfaces as a promise to implement certain key methods rather than a class to derive from. And so we tend to use different language for interfaces than for classes.

So finally the conclusion would be, an interface cannot implement another interface.

Hope this helps.

Kindly mark this as solved if my reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
This was selected as the best answer
VijoVijo
Hi Nagendra, that made sense. Let me expand a bit here, as to the need and what needs to be done in Salesforce
Interfaces define behaviour as you have said, and my intention was to group them so that i could kinda have a master interface that can be implemented. Lets say i have interfaces say
1. Interface : CanWalk, method : walk()
2. Interface : CanSwim, method : swim()
3. Interface : CanCrawl, method : crawl()

I would then like to define an interface that is a combination of the above like
1. Interface : Human, which has CanWalk, CanSwim, CanCrawl
2. Interface : Reptile, which has CanSwim, Can Crawl

Abstract class. since being a class, can only be used by another class to extend it, and the issue is that i can only do one extend.

Coming to Salesforce,
For an interface to 'implement' another interface(Schedulable), 
public interface CustomSchedulable extends Schedulable{
    //write your methods here
}

But this means that in order to achieve my 'Human' interface, i have to chain them via intermediate interface implementations, which is a pain.

Thank you for you response.. it gave me direction.