方法级联调用
方法级联调用(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
参见
- 流式接口
- 管道 (Unix)
- Nesting (computing)
- 生成器模式
- 诅咒金字塔_(编程)
- 方法链式调用
参考文献
- Beck, Kent. . Prentice Hall. 1997. ISBN 978-0134769042.
- . [2022-10-13]. (原始内容存档于2022-09-06).
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.