What is an Interface in Java?
Interfaces are communication contract between the external world and your system. Well defined interfaces can provide compile time validation and save you and consumers of your system a lot of troubles.You actually do have multiple implementations of an interface inside your system.
Interfaces can help in automated testing, when you need to isolate certain components. Yet concrete classes can be mocked as well.
Sometime there arises question: What is difference between interface and inheritance?
Inheritance has been used when the new class IS A class having the same features of the base one and it extends its basic behaviour with additional and more specialised methods.
An interface has been used when the class implementing it is capable of performing some actions described by the interface or needs some form of classification.
For instance something like offering a content to be printed is a general feature of a class, not specifically related to what the class actually does, so I would write an IPrintable interface implemented by the class offering content to be printed.
To learn more about Java Concepts at TCCI.
Call us @ 9825618292
Visit us@ http://tccicomputercoaching.com/programming-course/
No comments:
Post a Comment