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:
Completely agree with you. By doing so, Oracle is moving away from the golden SOLID OOP principles.
Post a Comment