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
// Bad example of configuration. | |
class BlogPosts | |
{ | |
// The class is coupled to the standard library configuration. Testing and handling | |
// future changes is hard. | |
public Posts FetchAll() | |
{ | |
Uri url = ConfigurationManager.AppSettings["blogPostsUrl"]; | |
// Fetch using url. |
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
class InstanceRenderer : IRender | |
{ | |
public void Render() | |
{ | |
// Render game... | |
} | |
} | |
// Usage | |
var instanceRenderer = new InstanceRenderer(); |
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
// Cannot implement interface. Unable to pass this around. | |
static class StaticRenderer | |
{ | |
public static void Render() | |
{ | |
// Render game... | |
} | |
} | |
// Usage within Game |
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
class SingletonRenderer : IRender | |
{ | |
private static SingletonRenderer instance; | |
// Prevents the class from being instantiated without getting | |
// an instance via the Instance method. | |
private SingletonRenderer() { } | |
public static SingletonRenderer Instance | |
{ |
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 class ValidationResults | |
{ | |
public ValidationResults(List<Error> errors) | |
{ | |
this.Errors = errors; | |
} | |
public List<Error> Errors { get; private set; } | |
public static ValidationResults Empty() |
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 class RootValidator | |
{ | |
private readonly IValidator[] validators; | |
public RootValidator(params IValidator[] validators) | |
{ | |
this.validators = validators; | |
} | |
public ValidationResults Validate(OrderInformation request) |
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
class OrderInformation | |
{ | |
[Required] | |
public BillingAddress BillingAddress { get; set; } | |
public bool BillingAddressSameAsDelivery { get; set; } | |
// More properties... | |
} |
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 void Domain(RedemptionService service) { | |
IRedemptionResult result = service.Redeem(); | |
result.Process(this); | |
} |
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 IRedemptionResult Redeem() { | |
if (httpStatus == 200) { | |
// Code... | |
new SuccessfulRedemption(); | |
} | |
else { | |
// Parse errors | |
return new RedemptionFailure(errors) | |
} | |
} |
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 void Domain(RedemptionService service) { | |
Result result = service.Redeem(); | |
if (result.Success) { | |
// Domain logic for success | |
} | |
else { | |
// Domain logic for failure | |
} | |
} |