Last active
December 19, 2017 09:26
-
-
Save litichevskiydv/d3ce4be2ece7f53ace13a87e576fa19f to your computer and use it in GitHub Desktop.
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
public static class PrintOrdersGenerator | |
{ | |
public interface IPrintOrderBuilder | |
{ | |
IPrintOrderConfigurator WithEditionType(EditionType editionType); | |
IPrintOrderConfigurator WithCoverType(CoverType coverType); | |
IPrintOrderConfigurator WithPageSize(PageSize pageSize); | |
IPrintOrderConfigurator WithPaperType(PaperType paperType); | |
IPrintOrderConfigurator WithIllustrations(params Illustration[] illustrations); | |
IPrintOrderConfigurator WithFontSize(int fontSize); | |
IPrintOrderConfigurator WithCopiesCount(int copiesCount); | |
} | |
private class PrintOrderBuilder : IPrintOrderBuilder | |
{ | |
public EditionType EditionType { get; private set; } | |
public CoverType CoverType { get; private set; } | |
public PageSize PageSize { get; private set; } | |
public PaperType PaperType { get; private set; } | |
public Illustration[] Illustrations { get; private set; } | |
public int FontSize { get; private set; } | |
public int CopiesCount { get; private set; } | |
public PrintOrderBuilder() | |
{ | |
EditionType = EditionType.Standard; | |
CoverType = CoverType.Hard; | |
PageSize = PageSize.Quarto; | |
PaperType = PaperType.Inkjet; | |
Illustrations = new Illustration[0]; | |
FontSize = 14; | |
CopiesCount = 1; | |
} | |
public IPrintOrderBuilder WithEditionType(EditionType editionType) | |
{ | |
EditionType = editionType; | |
return this; | |
} | |
public IPrintOrderBuilder WithCoverType(CoverType coverType) | |
{ | |
CoverType = coverType; | |
return this; | |
} | |
public IPrintOrderBuilder WithPageSize(PageSize pageSize) | |
{ | |
PageSize = pageSize; | |
return this; | |
} | |
public IPrintOrderBuilder WithPaperType(PaperType paperType) | |
{ | |
PaperType = paperType; | |
return this; | |
} | |
public IPrintOrderBuilder WithIllustrations(params Illustration[] illustrations) | |
{ | |
Illustrations = illustrations; | |
return this; | |
} | |
public IPrintOrderBuilder WithFontSize(int fontSize) | |
{ | |
FontSize = fontSize; | |
return this; | |
} | |
public IPrintOrderBuilder WithCopiesCount(int copiesCount) | |
{ | |
CopiesCount = copiesCount; | |
return this; | |
} | |
} | |
public static PrintOrder Create( | |
Func<IPrintOrderBuilder, IPrintOrderBuilder> printOrderConfiguration) | |
{ | |
var builder = new PrintOrderBuilder(); | |
printOrderConfiguration(builder); | |
return new PrintOrder( | |
builder.EditionType, | |
builder.CoverType, | |
builder.PageSize, | |
builder.PaperType, | |
builder.Illustrations, | |
builder.FontSize, | |
builder.CopiesCount | |
); | |
} | |
public static PrintOrder Create() | |
{ | |
return Create(x => x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment