S
sasuke
Hi all.
I've been recently trying to design a small command line translator
application. I can come up with three possibilities as to the way in
which the interface which hides the translation magic behind the
scenes can be designed:
// The stateless verbose contract [SLVC]
public interface ITranslator {
String translate(String text, Locale fromLocale, Locale toLocale);
}
// The stateful minimalistic contract [SFMC]
public interface ITranslator {
String translate(String text);
}
// The stateful verbose contract [SFVC]
public interface ITranslator {
String translate(String text);
void setFromLocale(Locale fromLocale);
void setToLocale(Locale toLocale);
}
Here is my interpretation of the three:
- The SLVC places the responsibility of handling the locale
information on the calling class. The implementation class can be very
well implemented using the Singleton design pattern since no
additional information is required when translating text.
- The SFMC places the responsibility of handling locale information on
the implementation class. One of the ways in which this can be done is
make the implementation class provide setter or hook methods for
setting the locale information though any other approach for
retrieving the locale information can be used.
- The SFVC is a verbose version of SFMC which mandates the
implementation class provide hooks for setting the Locale information
i.e. mandates the implementation class be Stateful.
I'm personally leaning towards the first approach but would very much
like to hear what is the general thought process which goes behind
when designing interfaces in general. Comments and suggestions
appreciated.
../sasuke
P.S.: Pardon the silly categorization; I came up with those on a
whim. ;-)
I've been recently trying to design a small command line translator
application. I can come up with three possibilities as to the way in
which the interface which hides the translation magic behind the
scenes can be designed:
// The stateless verbose contract [SLVC]
public interface ITranslator {
String translate(String text, Locale fromLocale, Locale toLocale);
}
// The stateful minimalistic contract [SFMC]
public interface ITranslator {
String translate(String text);
}
// The stateful verbose contract [SFVC]
public interface ITranslator {
String translate(String text);
void setFromLocale(Locale fromLocale);
void setToLocale(Locale toLocale);
}
Here is my interpretation of the three:
- The SLVC places the responsibility of handling the locale
information on the calling class. The implementation class can be very
well implemented using the Singleton design pattern since no
additional information is required when translating text.
- The SFMC places the responsibility of handling locale information on
the implementation class. One of the ways in which this can be done is
make the implementation class provide setter or hook methods for
setting the locale information though any other approach for
retrieving the locale information can be used.
- The SFVC is a verbose version of SFMC which mandates the
implementation class provide hooks for setting the Locale information
i.e. mandates the implementation class be Stateful.
I'm personally leaning towards the first approach but would very much
like to hear what is the general thought process which goes behind
when designing interfaces in general. Comments and suggestions
appreciated.
../sasuke
P.S.: Pardon the silly categorization; I came up with those on a
whim. ;-)