blog

Home / DeveloperSection / Blogs / Interface in oops

Interface in oops

ANkita gupta 2006 30-Apr-2015

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;
        @Override
        public int createSessionId() {
            return lastSessionId++;
    }
}

In above example of an interface in Java, SessionIDCreator is an interface while SerialSessionIDCreator is an implementation of the interface.


Updated 23-Feb-2018

Leave Comment

Comments

Liked By