• 请不要在回答技术问题时复制粘贴 AI 生成的内容
wezzard
V2EX  ›  程序员

關於 Swift 和 Liskov Substitution Principle

  •  
  •   wezzard · Nov 3, 2014 · 2944 views
    This topic created in 4235 days ago, the information mentioned may be changed or developed.
    貌似 Swift 完美貫徹了 Liskov Substitution Principle,像蘋果 UIKit 裏面 UITableView 繼承自 UIScrollView,然後 override 掉了 UIScrollView 的 delegate property 所 conformed to 的 protocol 的這種做法在 Swift 裏面就不行了。但是我上維基看了下 Liskov Substitution Principle 的定義,感覺以上這種做法並不違反 Liskov Sbustituion Principle 啊。

    Let q(x) be a property provable about objects x of type T. Then q(y) should be provable for objects y of type S, where S is a subtype of T.

    但是 UITableViewDelegate protocol 繼承自 UIScrollViewDelegate protocol 啊。
    1 replies    2014-11-03 11:19:18 +08:00
    lingoerer
        1
    lingoerer  
       Nov 3, 2014
    这个和死不死威夫特没关系,基本上所有抠卡和抠卡塔基里面的东西都遵循李氏代换……这是面向那谁的基础啊……
    顺便,有个值得一玩的东西叫做NSProxy,死威夫特里面没有OC里面有~~李氏代换的原则遇到这东西会很好玩
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   940 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:18 · PVG 04:18 · LAX 13:18 · JFK 16:18
    ♥ Do have faith in what you're doing.