Files
2nd/10_Wiki/Topic_Programming/Architecture/Polymorphism (다형성).md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

4.7 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-polymorphism-다형성 Polymorphism (다형성) 10_Wiki/Topics verified self
Polymorphism
다형성
Polymorphism in Engine Architecture
none A 0.9 applied
oop
type-system
design
architecture
2026-05-10 pending
language framework
python-cpp-rust oop

Polymorphism (다형성)

매 한 줄

"매 same interface, 매 different behavior". Polymorphism은 매 하나의 symbol/call-site가 매 runtime 또는 compile-time에 매 여러 type에 대해 매 적절히 dispatch되는 매 type-system property. 매 1967 Strachey 분류 (parametric / ad-hoc) 이후 매 OOP / functional / trait-based 모든 paradigm의 매 backbone.

매 핵심

매 4가지 form

  • 매 Subtype (inclusion): 매 Animal a = new Dog() — 매 Liskov Substitution.
  • 매 Parametric (generic): 매 List<T>, 매 fn id<T>(x: T) -> T.
  • 매 Ad-hoc (overloading): 매 f(int) vs 매 f(string) — 매 compile-time dispatch.
  • 매 Coercion: 매 int → float 매 implicit conversion.

매 Dispatch 축

  • Single dispatch: 매 receiver type 하나로 결정 (Java, Python).
  • Multiple dispatch: 매 모든 argument type으로 결정 (Julia, CLOS).
  • Static: 매 compile-time (templates, traits with monomorphization).
  • Dynamic: 매 runtime (vtable, duck typing).

매 응용

  1. Engine architecture: Renderer interface → VulkanRenderer / MetalRenderer.
  2. Generic containers: Vec<T> / HashMap<K,V>.
  3. Strategy pattern: Sorter 매 inject 다른 algorithm.

💻 패턴

Subtype polymorphism (Python)

from abc import ABC, abstractmethod

class Renderer(ABC):
    @abstractmethod
    def draw(self, scene): ...

class VulkanRenderer(Renderer):
    def draw(self, scene): scene.submit_vulkan()

class MetalRenderer(Renderer):
    def draw(self, scene): scene.submit_metal()

def render(r: Renderer, s): r.draw(s)

Parametric (Rust generics + monomorphization)

fn largest<T: PartialOrd>(list: &[T]) -> &T {
    let mut largest = &list[0];
    for item in list { if item > largest { largest = item; } }
    largest
}
// Compiler emits largest_i32, largest_f64, ... — zero-cost.

Ad-hoc (C++ overloading)

int  f(int x)        { return x * 2; }
auto f(double x)     { return x + 0.5; }
auto f(std::string s){ return s + "!"; }

Multiple dispatch (Julia)

collide(a::Asteroid, b::Asteroid) = "rock-rock"
collide(a::Asteroid, b::Ship)     = "ship dies"
collide(a::Ship,     b::Ship)     = "fleet battle"
collide(Asteroid(), Ship())  # → "ship dies"

Trait objects (Rust dynamic dispatch)

trait Draw { fn draw(&self); }
let shapes: Vec<Box<dyn Draw>> = vec![Box::new(Circle), Box::new(Square)];
for s in &shapes { s.draw(); }  // vtable lookup

Duck typing (Python)

class File:    def read(self): return "file"
class Network: def read(self): return "net"
def consume(src): print(src.read())  # 매 .read() 있으면 OK

Type class (Haskell)

class Eq a where
  (==) :: a -> a -> Bool

instance Eq Int    where x == y = ...
instance Eq String where x == y = ...

매 결정 기준

상황 Approach
매 hot loop, 매 known types Parametric (monomorphized)
매 plugin / extension point Subtype (dyn / interface)
매 numeric tower, 매 binary op Multiple dispatch
매 internal lib Duck typing / structural

기본값: Parametric for libraries, subtype for extension points.

🔗 Graph

🤖 LLM 활용

언제: API 설계, refactoring 시 dispatch 선택, 매 generic vs interface 결정. 언제 X: 매 단일 type의 simple script (overengineering).

안티패턴

  • 매 Type-checking ladder: 매 if isinstance(x, A): ... elif isinstance(x, B): 매 dispatch 회피.
  • 매 Deep inheritance: 매 5+ level subtype tree → composition 으로 대체.
  • 매 dyn 남용: 매 hot path 매 vtable 매 overhead.
  • 매 Yo-yo problem: 매 method override가 매 subclass-superclass 매 ping-pong.

🧪 검증 / 중복

  • Verified (Cardelli & Wegner 1985, Pierce "Types and Programming Languages" 2002).
  • 신뢰도 A.
  • 중복: Polymorphism (다형성) redirects here.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — 4 forms + dispatch axes + working examples