Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 565 Bytes

2_OCP_code_problem.md

File metadata and controls

19 lines (15 loc) · 565 Bytes

Below is an example class not following the OCP

class Customer {
  int CustomerType = 0;

  int GetDiscount() {
    if (this.CustomerType == 1) {
      return 50;
    } else {
      return 10;
    }
  }
}

What happens when I need to cater for a new CustomerType in the future? If I find myself needing to change class implementation, then I am doing it wrong. What changes can be made to better follow the OCP ?

« back to readme.md | view the refactored code »