[英]Android: A PendingIntent is a form of an Intent, then why isn't PendingIntent a subclass of Intent?
They say that 他们说
Generally, when there exists an "is-a" relationship between two entities, there is an inheritance relationship in terms of OOP. 通常,当两个实体之间存在“是”关系时,就存在面向对象的继承关系。
For example 例如
"A mountain bike is a bicycle." “山地自行车就是自行车。”
So MountainBike
is a subclass of Bicycle
as well, as a MountainBike
inherits the properties of Bicycle
, and has some of its own as well. 因此, MountainBike
也是Bicycle
的子类, MountainBike
继承了Bicycle
的属性,并且也具有一些自己的属性。
Now, generally speaking a PendingIntent is an Intent, isn't it? 现在,通常来说PendingIntent是Intent,不是吗? So why is a PendingIntent a subclass of Intent? 那么为什么PendingIntent是Intent的子类?
Reference: Developer docs 参考: 开发人员文档
generally speaking a PendingIntent is an Intent, isn't it? 一般来说,PendingIntent是Intent,不是吗?
A PendingIntent
can be best thought of as a wrapper around an Intent
, identifying an operation to be performed (start an activity, start a service, send a broadcast) and a security context under which that operation should be performed. 最好将PendingIntent
视为一个围绕Intent
的包装,标识要执行的操作(启动活动,启动服务,发送广播)以及应在其下执行该操作的安全上下文。
Hence, a "has-a" relationship model is a perfectly reasonable approach here. 因此,“具有”关系模型在这里是一种完全合理的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.