Should we avoid to use Object as the input parameter/ output value of a method?
Posted
by developer.cyrus
on Stack Overflow
See other posts from Stack Overflow
or by developer.cyrus
Published on 2010-05-19T12:13:17Z
Indexed on
2010/05/19
12:30 UTC
Read the original article
Hit count: 196
Take Java syntax as an example, though the question itself is language independent. If the following snippet takes an object MyAbstractEmailTemplate
as input argument in the method setTemplate
, the class MyGateway
will then become tightly-coupled with the object MyAbstractEmailTemplate
, which lessens the re-usability of the class MyGateway
.
A compromise is to use dependency-injection to ease the instantiation of MyAbstractEmailTemplate
. This might solve the coupling problem
to some extent, but the interface is still rigid, hardly providing enough ?exibility to
other developers/ applications.
So if we only use primitive data type (or even plain XML in web service) as the input/ output of a method, it seems the coupling problem no longer exists. So what do you think?
public class MyGateway {
protected MyAbstractEmailTemplate template;
publoc void setTemplate(MyAbstractEmailTemplate template) {
this.template = template;
}
}
© Stack Overflow or respective owner