Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between required and Provided interfaces

I know in general :

an interface is a reference type, it is similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces ?

But what is the difference between required and Provided interfaces ?

like image 553
Micha agus Avatar asked May 04 '14 12:05

Micha agus


People also ask

What is a required interface?

A required interface is an interface that is defined by the client of an interaction that specifies what a supplier component needs to do so that it can be used in that interaction. A good example of required interface is an interface commonly referred to as “comparable”.

What is interface describe required and provided interface with UML notations?

In UML modeling, interfaces are model elements that define sets of operations that other model elements, such as classes, or components must implement. An implementing model element realizes an interface by overriding each of the operations that the interface declares.

What is interface class diagram?

An interface is a classifier that declares of a set of coherent public features and obligations. An interface specifies a contract. In UML 1.4 interface was formally equivalent to an abstract class with no attributes and no methods and only abstract operations.


3 Answers

Provided and required interface always refer to the concept of interface, indicating the point of view.

I hope the following diagrams sheds some light on the subject.

enter image description here

On the implementation level a provided interface is the interface implemented by a class (in the most common sense, e.g. a class B implements the interface I). Required interface would be any use of an interface by a component (e.g. if a class A defines a method that has the interface I as a parameter, this means that class A has a required interface I).

like image 155
Aleks Avatar answered Nov 10 '22 01:11

Aleks


I think that you are confusing interface in general sense and language specific construct that is also called interface.

In general sense interface means point of intreaction between two parts/objects/system. At very low level, you can say that all public members (methods + fields) of an object compose its intreface.

At higher abstraction level programmers often think about API as interface for library/system. But that does not mean that this API consist of just one Java interface. The API contains all objects, methods, contsructors, config files... that are ment to be used by users of the library.That is probably what is ment by your required and provided interfaces.

If you write java libary, you usually require the API of Java standard library (everything in java package) - that would be the required interface. (it can be provided by JVM of any implementation, for example Android is using the same interface as Java but it is not java) On the other end your library would also expose some interface - the way people could use your library - that would be called the provided interface. (again if I say interface I don't mean one java interface, it would be probably mix of several interfaces + implementations + some value classes)

One other term you might encounter is SPI Service Provider Interface which is similar to API, but the users of SPI don't make calls to this interface, but rather implement it and expose it back to the original system. It's a way to describe interface for plugins.

like image 22
Hurda Avatar answered Nov 10 '22 01:11

Hurda


Required and provided interfaces appear to be UML-related terms, where a provided interface describes functionality offered by a class and required interfaces describe functionality needed by another class: further reading.

In Java, all interfaces are the same; there is no distinction between provided/required.

Previous link no longer work, but https://www.ibm.com/developerworks/rational/library/dec04/bell/index.html can be of help

like image 45
Duncan Jones Avatar answered Nov 09 '22 23:11

Duncan Jones