docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합

이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
This commit is contained in:
Antigravity Agent
2026-07-05 00:39:13 +09:00
parent 9148c358d0
commit e9cbf23ab5
1356 changed files with 0 additions and 12831 deletions
@@ -0,0 +1,77 @@
---
id: csharp-polymorphism
title: "C# Polymorphism"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["virtual override C#", "method overriding C#", "C# 다형성"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.85
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["csharp", "programming-language", "w3schools", "oop", "polymorphism"]
raw_sources: ["https://www.w3schools.com/cs/cs_polymorphism.php"]
applied_in: []
github_commit: ""
---
# [[CSharp Polymorphism]]
## 🎯 한 줄 통찰 (One-line insight)
C# requires the EXACT same two-keyword pairing already confirmed for modern C++ in Topic_CPP — `virtual` on the base class method, `override` on each derived class's replacement — and this chapter goes further than the CPP chapter did by explicitly demonstrating the FAILURE case first: without `virtual`/`override`, calling `animalSound()` through an `Animal`-typed reference to a `Pig`/`Dog` object prints the BASE class's message every time, because (per the tutorial's own explanation) same-named methods without these keywords simply aren't polymorphic at all — they're just separately-named methods that happen to share an identifier. [S1]
## 🧠 핵심 개념 (Core concepts)
- **Polymorphism ("many forms")** — occurs among classes related by inheritance; lets a single action be performed in different ways depending on the actual object type. [S1]
- **Without `virtual`/`override`** — same-named methods in base and derived classes do NOT achieve polymorphism; calling the method through a base-typed reference always runs the BASE class's version, regardless of the actual object's derived type. [S1]
- **`virtual` keyword** — placed on the BASE class method to allow it to be overridden. [S1]
- **`override` keyword** — placed on each DERIVED class's replacement method, required alongside base `virtual` to achieve true polymorphic dispatch. [S1]
- **Base-typed reference, derived object** — `Animal myPig = new Pig();` — the variable's declared TYPE is the base class, but the actual OBJECT is the derived class; with `virtual`/`override`, the call resolves to the derived class's implementation at runtime. [S1]
## 📖 세부 내용 (Details)
- Without virtual/override (the "not the output I was looking for" case): base and derived `Animal`/`Pig`/`Dog` each define their own `animalSound()`, but `Animal myPig = new Pig(); myPig.animalSound();` prints `"The animal makes a sound"` for ALL three objects, not the derived versions. [S1]
- With virtual/override: `public virtual void animalSound()` in `Animal`, `public override void animalSound()` in `Pig` and `Dog``myAnimal.animalSound()` prints `"The animal makes a sound"`, `myPig.animalSound()` prints `"The pig says: wee wee"`, `myDog.animalSound()` prints `"The dog says: bow wow"` — each resolves to its OWN class's implementation. [S1]
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **virtual/override 페어링이 C++와 완전히 동일**: 기반 클래스에 virtual, 파생 클래스에 override를 붙여야 다형성이 작동한다는 규칙이 Topic_CPP의 Virtual Functions 챕터(C++11의 override 키워드 포함)와 차이가 없다는 점이 확인됨. [S1]
- **실패 사례를 먼저 보여줌으로써 virtual의 필요성을 명확히 함**: Topic_CPP의 Virtual Functions 챕터와 달리, 이번 챕터는 virtual/override 없이 먼저 실행해 "기대와 다른 출력"이 나오는 것을 보여준 뒤에야 virtual/override를 도입한다는 점이 교육적 구성의 차이로 확인됨. [S1]
## 🛠️ 적용 사례 (Applied in summary)
Animal 기반 클래스와 Pig/Dog 파생 클래스가 각각 다른 animalSound()를 구현하고, virtual/override 없이는 모두 기반 클래스 메시지만 출력되다가 virtual/override를 추가하면 각 동물 고유의 소리가 출력되는 before/after 비교가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
## 💻 코드 패턴 (Code patterns)
Without vs. with virtual/override — same call site, different resolved method (C#):
```csharp
// Without virtual/override -- always prints base class message
class Animal { public void animalSound() { Console.WriteLine("The animal makes a sound"); } }
class Pig : Animal { public void animalSound() { Console.WriteLine("The pig says: wee wee"); } }
Animal myPig1 = new Pig();
myPig1.animalSound(); // "The animal makes a sound" -- NOT polymorphic
// With virtual/override -- resolves to the actual object's type
class Animal2 { public virtual void animalSound() { Console.WriteLine("The animal makes a sound"); } }
class Pig2 : Animal2 { public override void animalSound() { Console.WriteLine("The pig says: wee wee"); } }
Animal2 myPig2 = new Pig2();
myPig2.animalSound(); // "The pig says: wee wee" -- polymorphic
```
## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.85
- **중복 검사 결과:** 신규 생성 (New discovery)
## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C# Tutorial]]
- **관련 개념:** [[CSharp Inheritance]], [[CSharp Abstract]], [[CPP Virtual Functions]], [[CPP Polymorphism]]
- **참조 맥락:** Polymorphism & Abstract 섹션 — Abstraction 챕터로 이어짐.
## 📚 출처 (Sources)
- [S1] W3Schools — C# Polymorphism — https://www.w3schools.com/cs/cs_polymorphism.php
## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C# Polymorphism" page (Astra wiki-curation, P-Reinforce v3.1 format).