Monday, January 28, 2013

Interface use should remain as concept or general rule ??


Use of the interface as general rule?

After years of JEE development I've seen different release of JEE specification.


Using interface every where was a development best practice.So every service should implement and interface:)

Service service = new ServiceImpl();


But strange, the last specification on the JEE does not heavily rely on the use of interface (the famous local and remote inteface of ejb 1.x, ejb2.x...ejb3.0)?


With EJB 3.0 the use of the interfaces were mandatory (local and remote interface) . But with the latest specification it was no more the case(the declaration of a stateless bean).

  • EJB 3.1

@Statelesspublic class CrudService{
}
 Even with the dependency injection, no need (for any class) to implement an interface to be usable within the CDI context.




Do we still need to do it? 

But, do we still need to use it systematically within standard jee project (normal jee project).

Disadvantage:

  • it double the number of the artifact and significantly increase the complexity 
  • it is  absolutely not funny to read javadoc twice
  • the navigation within the IDE is less fluent


But how should this remain used?

The use of interface should remain as concept and not as general rule (systematic) for any service, business component.. within the project:

  • the strategy pattern : several implementation of a strategy or an algorithm(failure strategy, success strategy..)
  • within the case of layer abstraction (separation)
  • within the framework development project: api design and intensive need of abstraction..
Reference:
http://www.adam-bien.com/roller/abien/entry/how_to_deal_with_interfaces
http://www.adam-bien.com/roller/abien/entry/service_s_new_serviceimpl_why



2 comments:

Sandeep Bhandari said...

Completely agree with you. By doing so, Oracle is moving away from the golden SOLID OOP principles.

Sandeep Bhandari said...
This comment has been removed by the author.

My favorites blogs

  • Le 9 avril 2014, Xebia et Cellenza ont accueillis le troisième meetup du French Kanban User Group. Cette soirée exceptionnelle a permis, aux membres du FKU...
    55 minutes ago
  • *Adam Bien: When the Warsaw JUG (http://warszawa.jug.pl) was founded? What was the very first meeting?* We had our first meeting in November 2006 with a...
    1 day ago
  • A previous post introduced some features of using Scala with Vert.x. This post covers how to publish Rest web services in an elegant and simple fashio...
    1 year ago