Swift์—์„œ์˜ ์ƒ์†์€ ๋‹ค๋ฅธ ์–ธ์–ด์™€ ๋น„์Šทํ•˜๋‹ค.

Inheritance

  • Base Class
    • ๋‹ค๋ฅธ class๋กœ๋ถ€ํ„ฐ ์ƒ์†๋ฐ›์ง€ ์•Š์€ class
  • NSObject ์ƒ์† ๋ฐ›์„ ํ•„์š” ์—†์Œ
    • Objective-C์˜ ๊ฒฝ์šฐ run-time์— ํ•„์š”ํ•œ ๋ชจ๋“  ๋™์ž‘๋“ค์˜ ๊ธฐ๋ณธ์ด NSObject์— ๊ตฌํ˜„๋˜์–ด ์žˆ์Œ
    • Objective-C๋กœ ๊ตฌํ˜„๋œ framework์™€ ๋งž๋ฌผ๋ ค ๋™์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ NSObject๋ฅผ ์ƒ์† ๋ฐ›์•„์•ผ ํ•  ๊ฒฝ์šฐ๋„ ์žˆ์Œ
      • NSCoding

Overriding property

  • superclass์˜ getter, setter ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
  • observer ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
  • read-only โ†’ read-write O
  • read-write โ†’ read-only ๋ถˆ๊ฐ€๋Šฅ
    class Car: Vehicle {
        var gear = 1
        override var description: String {
            return super.description +  "in gear"
        }
    }

preventing overrides

  • final ํ‚ค์›Œ๋“œ๋ฅผ ํ†ตํ•ด ์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Œ
  • method, property, subscript, class
  • Static Dispatch ๋•Œ๋ฌธ์— ์ปดํŒŒ์ผ ์†๋„๊ฐ€ ๋” ๋นจ๋ผ์งˆ ์ˆ˜ ์žˆ์Œ