Please have a look at following piece of code:
public interface CultureService
{
List<Culture> GetCultures();
IsCultureSupported(Culture culture);
Culture GetFallbackCulture();
}
We found that most of the consumers first call IsCultureSupported to validate if their culture is supported or not. And if culture is not supported, they call GetFallbackCulture():
public CallingMethod()
{
if(!cultureManager.IsCultureSupported(currentCulture))
{
currentCulture=cultureManager.GetFallbackCulture();
}
.
.
.
}
As per Single Responsibility Principle (and other OOPs rules), is it ok to introduce a function (in CultureManager) like:
function GetFallbackCultureIfInvalid(Culture culture)
{
if(this.IsCultureSupported(culture)
{
return this.FallbackCulture();
}
}
Aucun commentaire:
Enregistrer un commentaire