What is an Interface

2019-01-29 11:46发布

问题:

With reference to UML diagrams, what is an interface? and can someone explain in more simpler words. I cant understand anything from googling it.

回答1:

An interface is like a template design for a class that contains no data or implemetnation; only definitions for methods, properties etc. These are abstract and cannot be instantiated but can be inherited from at which point all specified methods etc must be implemented by the concrete class inheriting the interface.



回答2:

An interface is a design item describing a behaviour. Classes implementing the interface will/must behave according to its definition. Interfaces are used to promote loose coupling and the base of many IoC patterns (Inversion of Control)



回答3:

A Interface is just a description of a class nothing concrete.

You use it to create a new class "with the same description" without knowing the concrete implementation.



回答4:

In one word: it's a contract. Every class that implements this contract (interface) will have to implement the methods defined on it.



标签: interface uml