Home > DeveloperSection > Blogs > Interface in oops

Interface in oops

Java OOPS 
1 Comment(s)
 604  View(s)
Rate this:
I am thankful to all for reading my blogs and correct my mistake and suggest me much better about oops.
I am going to discuss interface role in oops.
We already learned, objects define their interaction with the outside world through the methods that they expose.
Methods from the objects interface with outside world, the buttons on the front of your TV set, for e.g. ,
are the interface b/w you & the electrical wiring on the other side of its plastic casing. You press the "power" button to turn the television ON & OFF.
E.g. using interface.

interface SessionIDCreator extends Serializable, Cloneable{
        String TYPE = "AUTOMATIC";
        int createSessionId();
    class SerialSessionIDCreator implements SessionIDCreator{

        private int lastSessionId;
        public int createSessionId() {
            return lastSessionId++;

In above example of interface in JavaSessionIDCreator is an interface while SerialSessionIDCreator is a implementation of interface.


By Mayank Tripathi on   one year ago
Ankita good analogy for interfaces!!

But you must explain here how we use interfaces in our implementation and facilitates our OOPs designs with interfaces

Don't want to miss updates? Please click the below button!

Follow MindStick