When a method has more than 3 parameters, you can consider encapsulating the parameter as an object. Encapsulating the parameter as an object improves the readability of the code, and the Parameter object can be called by multiple methods, and if the delete parameter is added later, the method itself does not need to be modified, only the parameter object can be modified. Refactoring pre-code
Public class Registration { publicvoid Create (decimaldecimal credits) { // do work } }
Post-Refactoring Code
Public classRegistrationcontext { Public decimalAmount {Get;Set; } PublicStudent Student {Get;Set; } PublicIenumerable<course> Courses {Get;Set; } Public decimalCredits {Get;Set; } } Public classRegistration { Public voidCreate (Registrationcontext registrationcontext) {// do work } }
Refactoring Guide-Introducing Parameter objects (introduce Parameter object)