Last active
December 8, 2018 03:40
-
-
Save thaianhduc/ca2a238c764091e567faeafa7ce28eab to your computer and use it in GitHub Desktop.
A simple piece of code to demonstrate the code readability by looking at method's parameters.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class VerificationContext | |
{ | |
public string SpecialNotes { get; set; } | |
public ApplicantCv ApplicantCv { get; set; } | |
} | |
public class ApplicantCv | |
{ | |
public string ApplicantName { get; set; } | |
} | |
public class SeniorPosition : IVerifyingByPosition | |
{ | |
public bool Accept(VerificationContext context) | |
{ | |
return !string.IsNullOrWhiteSpace(context.SpecialNotes); | |
} | |
public void Verifying(VerificationContext context) | |
{ | |
// In a real project, there might be many lines in this method. | |
Console.WriteLine($"Special notes: {context.SpecialNotes}"); | |
Console.WriteLine($"You are passed when {context.ApplicantCv.ApplicantName} is Batman"); | |
} | |
} | |
public class JuniorPosition : IVerifyingByPosition | |
{ | |
public bool Accept(VerificationContext context) | |
{ | |
return string.IsNullOrWhiteSpace(context.SpecialNotes); | |
} | |
public void Verifying(VerificationContext context) | |
{ | |
Verifying(context.ApplicantCv); | |
} | |
private void Verifying(ApplicantCv applicantCv) | |
{ | |
// The method might be long | |
Console.WriteLine($"Welcome junior: {applicantCv.ApplicantName}"); | |
} | |
} | |
public interface IVerifyingByPosition | |
{ | |
void Verifying(VerificationContext context); | |
bool Accept(VerificationContext context); | |
} | |
public class HrDepartment | |
{ | |
public void VerifyApplicants(IEnumerable<VerificationContext> applicants) | |
{ | |
var byPositions = new List<IVerifyingByPosition> | |
{ | |
new JuniorPosition(), | |
new SeniorPosition() | |
}; | |
foreach (var app in applicants) | |
{ | |
byPositions.First(x => x.Accept(app)) | |
.Verifying(app); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment