跳至內容

方法級聯調用

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

方法級聯調用(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).