--- id: csharp-abstract title: "C# Abstraction" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["abstract class method 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", "abstraction"] raw_sources: ["https://www.w3schools.com/cs/cs_abstract.php"] applied_in: [] github_commit: "" --- # [[CSharp Abstraction]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Where C++ makes a class abstract IMPLICITLY (simply by containing at least one pure virtual function written as `virtual void f() = 0;`, with no dedicated "this class is abstract" keyword), C# makes it EXPLICIT with a dedicated `abstract` keyword on both the class AND each bodyless method (`abstract class Animal { public abstract void animalSound(); }`) β€” the same underlying restriction (cannot instantiate, must be inherited to be used, subclass MUST supply the missing method body) is enforced, but C# spells out the intent in the declaration itself rather than deriving it as a side-effect of the method's syntax. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Data abstraction** β€” hiding certain implementation details, showing only essential information to the user; achievable via abstract classes OR interfaces (interfaces deferred to the next chapter). [S1] - **`abstract` on a class** β€” creates a RESTRICTED class that cannot be used to instantiate objects directly (`new Animal()` on an abstract class is a compile error: "Cannot create an instance of the abstract class or interface"). [S1] - **`abstract` on a method** β€” declared with NO body (just a signature ending in `;`); only legal inside an abstract class; the body must be supplied by whichever derived class inherits it, using `override`. [S1] - **Mixed abstract classes** β€” an abstract class can freely combine abstract methods (no body) alongside regular, fully-implemented methods. [S1] - **Must be accessed via inheritance** β€” the ONLY way to use an abstract class's functionality is to inherit from it and instantiate the DERIVED class instead. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Illegal direct instantiation: `abstract class Animal { public abstract void animalSound(); public void sleep() { Console.WriteLine("Zzz"); } } ... Animal myObj = new Animal(); // Error`. [S1] - Full working example (Animal converted from the Polymorphism chapter into an abstract class): `abstract class Animal { public abstract void animalSound(); public void sleep() { Console.WriteLine("Zzz"); } } class Pig : Animal { public override void animalSound() { Console.WriteLine("The pig says: wee wee"); } } ... Pig myPig = new Pig(); myPig.animalSound(); myPig.sleep();` β€” the abstract method's body comes entirely from `Pig`, while `sleep()` (a regular method) is inherited unchanged. [S1] - Purpose stated directly: achieving security by hiding certain details and showing only the important parts of an object. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **abstractκ°€ ν΄λž˜μŠ€μ—λ„ λͺ…μ‹œμ  ν‚€μ›Œλ“œλ‘œ λΆ™μŒ**: C++λŠ” 순수 가상 ν•¨μˆ˜(`virtual void f() = 0;`) ν•˜λ‚˜λ§Œ μžˆμ–΄λ„ ν΄λž˜μŠ€κ°€ μ•”λ¬΅μ μœΌλ‘œ 좔상 ν΄λž˜μŠ€κ°€ 되고 λ³„λ„μ˜ "좔상 클래슀" ν‚€μ›Œλ“œκ°€ μ—†μ—ˆμ§€λ§Œ, C#은 클래슀 μžμ²΄μ—λ„ `abstract` ν‚€μ›Œλ“œλ₯Ό λͺ…μ‹œμ μœΌλ‘œ λΆ™μ—¬μ•Ό ν•œλ‹€λŠ” 점이 확인됨 β€” 같은 μ œμ•½(μΈμŠ€ν„΄μŠ€ν™” λΆˆκ°€, 상속 ν•„μˆ˜, νŒŒμƒ ν΄λž˜μŠ€κ°€ λ°˜λ“œμ‹œ κ΅¬ν˜„ 제곡)을 ν‘œν˜„ν•˜λŠ” 방식이 암묡적(C++) vs λͺ…μ‹œμ (C#)으둜 닀름. [S1] - **Polymorphism μ±•ν„°μ˜ Animal μ˜ˆμ œκ°€ κ·ΈλŒ€λ‘œ μž¬μ‚¬μš©λ¨**: μƒˆλ‘œμš΄ 예제λ₯Ό λ§Œλ“€μ§€ μ•Šκ³  직전 Polymorphism μ±•ν„°μ˜ Animal/Pig 예제λ₯Ό abstract둜 λ³€ν™˜ν•΄ μž¬μ‚¬μš©ν•œλ‹€λŠ” 점이 확인됨 β€” κ°œλ…μ„ μ²˜μŒλΆ€ν„° λ‹€μ‹œ μ„€λͺ…ν•˜μ§€ μ•Šκ³  이미 읡힌 μ½”λ“œλ₯Ό ν™•μž₯ν•˜λŠ” 방식. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) 좔상 λ©”μ„œλ“œ animalSound()와 일반 λ©”μ„œλ“œ sleep()을 ν•¨κ»˜ κ°€μ§„ abstract class Animal을 Pigκ°€ 상속해 animalSound()의 λͺΈμ²΄λ§Œ μ œκ³΅ν•˜κ³  sleep()은 κ·ΈλŒ€λ‘œ λ¬Όλ €λ°›μ•„ μ“°λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Abstract class mixing an abstract method (no body) and a regular method (C#): ```csharp abstract class Animal { public abstract void animalSound(); // no body -- must be overridden public void sleep() // regular method -- inherited as-is { Console.WriteLine("Zzz"); } } class Pig : Animal { public override void animalSound() { Console.WriteLine("The pig says: wee wee"); } } Pig myPig = new Pig(); myPig.animalSound(); // "The pig says: wee wee" myPig.sleep(); // "Zzz" ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C# Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSharp Polymorphism]], [[CSharp Interface]], [[CPP Templates]] - **μ°Έμ‘° λ§₯락:** Polymorphism & Abstract μ„Ήμ…˜μ˜ λ§ˆμ§€λ§‰ 챕터 β€” Interface μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C# Abstraction β€” https://www.w3schools.com/cs/cs_abstract.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Abstraction" page (Astra wiki-curation, P-Reinforce v3.1 format).