Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you please let me know how to use an interface when there are no implement classes for it?

For example, consider the Alert() interface in the Selenium jar.
Posted

1 solution

The interfaces which are never implemented by some class make no sense at all. An interface can be used in any sensible way only if there is one or more implementation.

Think about it: an interface without an implementation cannot be instantiated as an object. All objects which compile-time type is interface type in fact always have some different runtime type, which is, in absolutely all cases, is the type implementing the interface in question.

If you don't have such implementation, you can use the interface type only in some trivial (and totally useless) way, for example as a name. You can take a name of interface type, compare it with some strings, use reflection to find out the interface members and properties of those members, and so on. Perhaps this can be useful as a programming exercise, but can only be useful for some real software product only if, ultimately, this interface is used in some "implements" clause of some implementing type.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900