Reconstruction guide, zhangjin restructuring industrial value
When a method has more than three parameters, you can consider encapsulating the parameters into an object. Encapsulating a parameter into an object improves the readability of the code, and the parameter object can be called by multiple methods. if you add a delete parameter in the future, the method itself does not need to be modified, you only need to modify the parameter object. Pre-reconstruction code
Public class Registration {public void Create (decimal amount, Student student, IEnumerable <Course> courses, decimal credits) {// do work }}
Code after reconstruction
Public class RegistrationContext {public decimal Amount {get; set;} public Student {get; set;} public IEnumerable <Course> Courses {get; set;} public decimal Credits {get; set ;}} public class Registration {public void Create (RegistrationContext registrationContext) {// do work }}