Created
May 9, 2014 17:36
-
-
Save anonymous/cee8ab7ddf64a2893cfe to your computer and use it in GitHub Desktop.
remove DI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before refactoring | |
class ImageConverter | |
{ | |
public ImageConverer(IImageConvterFactory factory /* use DI */) | |
{ | |
this.factory = factory; | |
} | |
public void Convert() | |
{ | |
IImageConvertAlgorithm alg = this.factory.GetAlgorithm(); | |
// use alg | |
} | |
} | |
// after refactoring | |
class ImageConverterBase | |
{ | |
protected ImageConverterBase(IImageConvertAlgorithm alg) | |
{ ... } | |
public void Convert() | |
{ ... } | |
} | |
class ImageConverterLargeMemory : ImageConverterBase | |
{ | |
public ImageConverterLargeMemory() | |
: base(new ImageConvertAlgorithmLargeMemory()) | |
{ | |
} | |
} | |
class ImageConverterSmallMemory : ImageConverterBase | |
{ | |
public ImageConverterLargeMemory() | |
: base(new ImageConvertAlgorithmSmallMemory()) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment