Java Interfaces
Design Perspective
Chennai Java Summit - 2013

Manigandan Venkataraman
shivamanik@gmail.com
Agenda
●

Application

●

Interface – What is an Interface

●

Components and Interface

●

Java Interface

●

Abstraction & Interfaces

●

Design Patterns

●

Good Design Practices
Applications
●

Applications that can grow
●

Plugins and Addons

●

Examples
–
–

●

Application should grow
–

●

Browser - Firefox
IDE – Eclipse, Netbeans
Provide plugin/ addon design

How to design such an application???
Interface
●

What is an INTERFACE

●

Tell me the interface for this room
●

Doors

●

Windows

●

Interfaces are nothing but communication points

●

How do you interface with your Bike or Car

●

Interfaces to the Computer
●

USB, HDMI, VGA , Serial Ports

●

Will this device work with my computer????
Components
println

PrintWriter

Public Interfaces are API
sum(int,int)

MyCalculator
sub(int,int)

Component Interface = method signature + return type
Operation

WebService
operation
●

●

RMI – Stubs and
Skeletons
We need Remote
Interfaces to compile
the local code

●

●

Webservice
endpoints are
interfaces
Only interface and
NO LOGIC
Java Interface
●

A way to implement multiple inheritance

●

Interface is a collection of abstract methods
●

●

now, we can have default implemented methods too
.... :)

All methods in an interface are public
Abstraction
●

What does Abstract mean ???

●

I need to go to Mumbai – abstract statement
●

Whats missing
–
–
–

●

Means of transport
Date and time
Budget

I am travelling to Mumbai on Monday 7 am, by
Indigo – Concrete Statement
Abstraction
●

Your College Project
●

Abstract - ????
–
–
–

●

Problem Statement
Solution
Whats missing - How ??? The Implemention

Where's the Implementation
–

The whole project is the Implementation !!!! ;)
Abstraction
●

An idea without Implementation

●

Why do we need it??
●

Object Oriented Design

Interfaces have abstract methods
Abstraction and Interfaces
●

Runnable Interface
●

<Code>

●

What it does

●

JVM has to deal with unknown code

●

Its not aware of Our Code

●

Interface Design provides Loose Coupling

●

Eclipse Rich Client Platform

●

Netbeans Platform
Design Patterns
●

Mixture of Abstract Classes and Interfaces

●

No logic, only provides a guideline/approach

●

Upto to programmer to write an implementation
– logic
Good Design Practices
●

Program to an interface , not to implementation
●
●

●

Spring Framework
Code can grow, more implementations

clients remain unaware
●

●

●

of the specific types of objects they use, as long as the
object adheres to the interface
of the classes that implement these objects; clients only
know about the abstract class(es) defining the interface

Use of an interface also leads to dynamic binding and
polymorphism
Thank You

Java interfaces design perspective

  • 1.
    Java Interfaces Design Perspective ChennaiJava Summit - 2013 Manigandan Venkataraman shivamanik@gmail.com
  • 2.
    Agenda ● Application ● Interface – Whatis an Interface ● Components and Interface ● Java Interface ● Abstraction & Interfaces ● Design Patterns ● Good Design Practices
  • 3.
    Applications ● Applications that cangrow ● Plugins and Addons ● Examples – – ● Application should grow – ● Browser - Firefox IDE – Eclipse, Netbeans Provide plugin/ addon design How to design such an application???
  • 4.
    Interface ● What is anINTERFACE ● Tell me the interface for this room ● Doors ● Windows ● Interfaces are nothing but communication points ● How do you interface with your Bike or Car ● Interfaces to the Computer ● USB, HDMI, VGA , Serial Ports ● Will this device work with my computer????
  • 5.
  • 6.
  • 7.
    Operation WebService operation ● ● RMI – Stubsand Skeletons We need Remote Interfaces to compile the local code ● ● Webservice endpoints are interfaces Only interface and NO LOGIC
  • 8.
    Java Interface ● A wayto implement multiple inheritance ● Interface is a collection of abstract methods ● ● now, we can have default implemented methods too .... :) All methods in an interface are public
  • 9.
    Abstraction ● What does Abstractmean ??? ● I need to go to Mumbai – abstract statement ● Whats missing – – – ● Means of transport Date and time Budget I am travelling to Mumbai on Monday 7 am, by Indigo – Concrete Statement
  • 10.
    Abstraction ● Your College Project ● Abstract- ???? – – – ● Problem Statement Solution Whats missing - How ??? The Implemention Where's the Implementation – The whole project is the Implementation !!!! ;)
  • 11.
    Abstraction ● An idea withoutImplementation ● Why do we need it?? ● Object Oriented Design Interfaces have abstract methods
  • 12.
    Abstraction and Interfaces ● RunnableInterface ● <Code> ● What it does ● JVM has to deal with unknown code ● Its not aware of Our Code ● Interface Design provides Loose Coupling ● Eclipse Rich Client Platform ● Netbeans Platform
  • 13.
    Design Patterns ● Mixture ofAbstract Classes and Interfaces ● No logic, only provides a guideline/approach ● Upto to programmer to write an implementation – logic
  • 14.
    Good Design Practices ● Programto an interface , not to implementation ● ● ● Spring Framework Code can grow, more implementations clients remain unaware ● ● ● of the specific types of objects they use, as long as the object adheres to the interface of the classes that implement these objects; clients only know about the abstract class(es) defining the interface Use of an interface also leads to dynamic binding and polymorphism
  • 15.