Re: Another JUnit scenario
On 05/23/2010 10:03 AM, Rhino wrote:
Just to be clear, let's say that the class containing my displayLocales()
method is called LocalizationUtils and it is a static factory class. Are
you saying that the stream or writer or whatever should be configured in
the constructor of LocalizationUtils or in the class which CALLS
LocalizationUtils? I'm assuming you mean the latter but I just want to be
sure.
He was saying in the constructor of LocalizationUtils. However, static
factory classes have their own rules.
A (usually - always the disclaimer) better pattern is to include the Locale as
an argument to the factory method. Static state is an antipattern.
public class LocalizationUtils
{
/** Don't forget the private constructor! */
private LocalizationUtils(){}
/**
* Foo factory with default Locale.
* @return Foo instance with default Locale.
*/
public static Foo getFooInstance()
{
return new SubtypeOfFoo();
}
/**
* Foo factory with custom Locale.
* @param locale custom Locale.
* @return Foo instance with custom Locale.
*/
public static Foo getFooInstance( Locale locale )
{
return new SubtypeOfFoo( locale );
}
}
Remember, the only hard and fast rule of programming is that there are no hard
and fast rules of programming.
--
Lew