跳至內容

方法級聯呼叫

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

方法級聯呼叫(Method cascading)是物件導向程式設計語言中對同一個對象呼叫其多個方法時的一種語法糖。特別適用於實現流暢介面[1]

例如在Dart語言中:

a..b()
 ..c();

等價於單獨呼叫:

a.b();
a.c();

Visual Basic允許對同一個對象呼叫任意多次的方法或屬性:[2]

With ExpressionThatReturnsAnObject
  .SomeFunction(42)
  .Property = value
End With

With..End With塊在Visual Basic中可以巢狀:

With ExpressionThatReturnsAnObject
  .SomeFunction(42)
  .Property = value
  With .SubObject
    .SubProperty = otherValue
    .AnotherMethod(42)
  End With
End With

參見[編輯]

參考文獻[編輯]

  1. ^ Beck, Kent. Smalltalk Best Practice Patterns. Prentice Hall. 1997. ISBN 978-0134769042. 
  2. ^ With statement in MSDN. [2022-10-13]. (原始內容存檔於2022-09-06).