Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to a subsystem

 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,

there is an approach which I do not understand.

Some sources recommend to write a java-interface, implemented by one java-class. This construct can be used to connect to a subsystem.

In my eyes it makes no sense to have a java-interface, which is only implemented by one class. In this case, I would omit the interface and write only a POJO-class to connect to the subsystem. Interfaces are useful, if they are implemented by more then one class, and all these classes can be accessed through the interface-type. The caller does not know, which class he invokes, because he works only with the interface. That's the real intention of interfaces, I think. But what would be the benefit, if there is only one class who implement a java-interface? If I write this class without the interface, it would be the same.

Regards,
Oliver
 
dinesh pande
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several places where you just use the implementation and not the interface (ofcourse, assuming that there is no need for an interface).

At the same time, one must not forget the value of "Programming to interfaces and not to implementations". For example take a look at some of the design patterns available, how would you implement them with out using interfaces?

To conclude, if you are saying that one should have an interface for each of the classes available then it is incorrect. However, there will be some classes which will have interfaces and some with out.

Is'nt OOAD all about discussing the above ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic