V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wezzard
V2EX  ›  程序员

關於 Swift 和 Liskov Substitution Principle

  •  
  •   wezzard · 2014-11-03 09:27:55 +08:00 · 2323 次点击
    这是一个创建于 3434 天前的主题,其中的信息可能已经有所发展或是发生改变。
    貌似 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 条回复    2014-11-03 11:19:18 +08:00
    lingoerer
        1
    lingoerer  
       2014-11-03 11:19:18 +08:00
    这个和死不死威夫特没关系,基本上所有抠卡和抠卡塔基里面的东西都遵循李氏代换……这是面向那谁的基础啊……
    顺便,有个值得一玩的东西叫做NSProxy,死威夫特里面没有OC里面有~~李氏代换的原则遇到这东西会很好玩
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2827 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:15 · PVG 21:15 · LAX 06:15 · JFK 09:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.