{"meta":{"title":"복잡한 상속 계층 구조 간소화","intro":"Copilot Chat 는 여러 계층의 상속이 있는 클래스를 방지하기 위해 코드를 리팩터링하는 데 도움이 될 수 있습니다.","product":"GitHub Copilot","breadcrumbs":[{"href":"/ko/copilot","title":"GitHub Copilot"},{"href":"/ko/copilot/tutorials","title":"자습서"},{"href":"/ko/copilot/tutorials/copilot-cookbook","title":"GitHub Copilot 활용 안내서"},{"href":"/ko/copilot/tutorials/copilot-cookbook/refactor-code","title":"코드 리팩터링"},{"href":"/ko/copilot/tutorials/copilot-cookbook/refactor-code/simplify-inheritance-hierarchies","title":"상속 계층 구조 간소화"}],"documentType":"article"},"body":"# 복잡한 상속 계층 구조 간소화\n\nCopilot Chat 는 여러 계층의 상속이 있는 클래스를 방지하기 위해 코드를 리팩터링하는 데 도움이 될 수 있습니다.\n\n깊은 상속 계층 구조 또는 상속의 부적절한 사용은 유지 관리가 어려운 코드를 초래하게 되어, 클래스 간의 관계를 이해하거나 클래스 확장 시 문제를 일으키지 않고 확장하기 어려워질 수도 있습니다.\n\nCopilot Chat 는 상속 기반 디자인을 보다 유연한 컴퍼지션 기반 디자인으로 리팩터링할 것을 제안할 수 있습니다(상속보다 컴퍼지션 선호). 또한 상속 구조에 복잡성을 추가하지 않고도 시스템을 더 확장할 수 있도록 전략 또는 데코레이터와 같은 패턴을 적용하는 것이 좋습니다.\n\n## 예제 시나리오\n\n다음 C# 코드에는 각 클래스가 이전 클래스를 기반으로 빌드되는 깊은 상속 계층 구조가 있습니다. 그 결과 각 클래스에 어떤 속성이 있는지 알기 어렵게 만드는 긴 상속 체인이 만들어 집니다.\n\n이와 같은 여러 수준의 상속 계층 구조는 이해하고, 수정하고, 확장하기 어려울 수 있습니다.\n\n```csharp id=employee-class\npublic class Employee\n{\n    public string Name { get; set; }\n    public int EmployeeID { get; set; }\n}\n\npublic class Manager : Employee\n{\n    public int NumberOfTeams { get; set; }\n}\n\npublic class SeniorManager : Manager\n{\n    public string Region { get; set; }\n}\n\npublic class Director : SeniorManager\n{\n    public int NumberOfDepartments { get; set; }\n}\n\npublic class VicePresident : Director\n{\n    public string Division { get; set; }\n}\n\npublic class President : VicePresident\n{\n    public string Company { get; set; }\n}\n```\n\n## 예제 프롬프트\n\n이 경우에는 다른 클래스가 상속해야 하는 속성이 있는 부모 `Employee` 클래스를 사용하도록 결정할 수 있지만, 다른 모든 속성을 각 클래스에 개별적으로 정의하여 다른 상속을 방지할 수 있습니다.\n\n```copilot copy prompt ref=employee-class\nRefactor this code so that classes only inherit the properties of the Employee class. All of the other properties that each class currently inherits should instead be declared independently in each class definition.\n```\n\n## 응답 예제\n\n> \\[!NOTE] 다음 응답이 예제입니다. Copilot Chat 응답은 비결정적이므로 여기에 표시된 응답과 다른 응답을 얻을 수 있습니다.\n\nCopilot 는 다음 코드를 제안합니다.\n\n```csharp\npublic class Employee\n{\n    public string Name { get; set; }\n    public int EmployeeID { get; set; }\n}\n\npublic class Manager : Employee\n{\n    public int NumberOfTeams { get; set; }\n}\n\npublic class SeniorManager : Employee\n{\n    public int NumberOfTeams { get; set; }\n    public string Region { get; set; }\n}\n\npublic class Director : Employee\n{\n    public int NumberOfTeams { get; set; }\n    public string Region { get; set; }\n    public int NumberOfDepartments { get; set; }\n}\n\npublic class VicePresident : Employee\n{\n    public int NumberOfTeams { get; set; }\n    public string Region { get; set; }\n    public int NumberOfDepartments { get; set; }\n    public string Division { get; set; }\n}\n\npublic class President : Employee\n{\n    public int NumberOfTeams { get; set; }\n    public string Region { get; set; }\n    public int NumberOfDepartments { get; set; }\n    public string Division { get; set; }\n    public string Company { get; set; }\n}\n```\n\n## 추가 읽기\n\n* [GitHub Copilot 채팅에 대한 프롬프트 엔지니어링](/ko/copilot/concepts/prompting/prompt-engineering)\n* [GitHub 부필로트 사용에 대한 모범 사례](/ko/copilot/get-started/best-practices)"}