我们有 3 个类负责处理图像。老板让我合并它。我将它合并到一个文件中,但他说这是同一件事,我们需要将其合并到一般逻辑中。我们如何将这 3 个吸气剂合并成一个通用吸气剂?它们仅在传递给 Type.GetType() 的参数类型上有所不同。我们需要使用一个通用属性和一个通用 getter。
public class BonusImageHandler
{
private static IStorageProvider _BAstorageProvider;
private static IStorageProvider _BAWP8storageProvider;
private static IStorageProvider _M4MstorageProvider;
private static readonly object _lock = new object();
private static IStorageProvider BAStorageProvider
{
get
{
lock (_lock)
{
if (_BAstorageProvider == null)
{
lock (_lock)
{
var storageProviderType = Type.GetType(BLL.Providers.ConfigurationProvider.Instance.BAStorageProviderTypeName);
_BAstorageProvider = (IStorageProvider)Activator.CreateInstance(storageProviderType);
}
}
}
return _BAstorageProvider;
}
}
private static IStorageProvider BAWP8StorageProvider
{
get
{
lock (_lock)
{
if (_BAWP8storageProvider == null)
{
lock (_lock)
{
var storageProviderType = Type.GetType(BLL.Providers.ConfigurationProvider.Instance.BAWP8StorageProviderTypeName);
_BAWP8storageProvider = (IStorageProvider)Activator.CreateInstance(storageProviderType);
}
}
}
return _BAWP8storageProvider;
}
}
private static IStorageProvider M4MStorageProvider
{
get
{
lock (_lock)
{
if (_M4MstorageProvider== null)
{
lock (_lock)
{
var storageProviderType = Type.GetType(BLL.Providers.ConfigurationProvider.Instance.M4MStorageProviderTypeName);
_M4MstorageProvider= (IStorageProvider)Activator.CreateInstance(storageProviderType);
}
}
}
return _M4MstorageProvider;
}
}
}