This approach is preferable to using UIView
directly, as in
extension UIView {
func flash() {
...
}
}
because it lets programmers decide which UIView
subclasses they wish to make Flashable
, as opposed to adding flash
functionality "wholesale" to all UIView
s:
// This class has flashing functionality
class MyViewWithFlashing : UIView, Flashable {
...
}
// This class does not have flashing functionality
class MyView : UIView {
...
}
Essentially, this is an "opt in" approach, while the alternative approach forces the functionality without a way to "opt out".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…