• lua(仿单继承)


    --lua仿单继承
    Account = { balance = 0}
    
    function Account:new(o)
      o = o or {}
      setmetatable(o, self)--Account表本身作为o的metatable
      self.__index = self--自己作为自己的原型
      return o
    end
    
    function Account:deposit(v)
      self.balance = self.balance + v
    end
    
    function Account:withdraw(v)
      if v > self.balance then print("insufficient funds") end
      self.balance = self.balance - v
    end
    
    SpecialAccount = Account:new()--从Account继承所有操作
    
    function SpecialAccount:withdraw(v)
      if v - self.balance >= self:getLimit() then
        print("insufficient funds")
      end
      self.balance = self.balance - v
    end
    
    function SpecialAccount:getLimit()
      return self.limit or 0
    end
    
    
    s = SpecialAccount:new{limit = 1000.00}--s继承SpecialAccount,SpecialAccount继承Account
    s:deposit(100.00)

    这个没怎么看懂

  • 相关阅读:
    很难理解的三个设计模式
    设计模式思考(转)
    AOP
    CAP理论(摘)
    DDBS
    NoSql
    Enterprise Library 企业库
    padright padleft
    Process ProcessThread Thread
    053374
  • 原文地址:https://www.cnblogs.com/zzyoucan/p/4325804.html
Copyright © 2020-2023  润新知