OCP — Open Close Principle
OCP는 코드 수정을 최소화하고 확장을 용이하게 하는 원칙입니다.
Open-Closed Principle(OCP)은 수정 없이 코드의 기능을 확장할 수 있어야 한다고 강조합니다. 즉, 기존의 검증된 코드를 유지하면서 새로운 동작을 추가하는 것을 목표로 합니다. OCP를 위반하면 새로운 결제 방법을 추가할 때 주요 함수에 변경이 필요해지고, 이는 버그를 발생시킬 수 있습니다. 이를 방지하기 위해 전략 패턴이나 다형성을 활용할 수 있습니다.
OCP emphasizes extending code functionality without modifying existing code.
The Open-Closed Principle (OCP) states that code should be open for extension but closed for modification. This means that new behaviors should be added without altering the tested code, reducing the risk of introducing bugs. Violating this principle can happen when adding new payment methods requires changes to central functions, potentially leading to regression bugs. Utilizing design patterns like Strategy and polymorphism can help in adhering to OCP.