Skip to main content

Posts

Showing posts with the label Refactoring

Review - I

During code reviews, one of the things that is considered is the " Command Query Separation Principle " Violation. Operations should either do something and return nothing or return something and do nothing, NOT both. The common violations are Getter Methods having void as their return types and Setter methods having some return values . Getter Methods having void as their return types. For eg: void GetSalary(Employee emp) { Money salary; //Fetch Salary from some source. emp.Salary = salary; } Generally, these violations can be fixed by renaming the method name to Update. void UpdateSalary(Employee emp); Setter methods having some return values . For eg: bool SetDepartment(Employee emp); Here, it gets tricky. The programmer sets the department inside the method and wants the confirmation by the return value. There are other ways to handle this rather than sending the return value. Having a method HasDepartment() in the Employee, to check whether it has Department. Rai...