Objective-C继承(Inheritance)——有关术语

超类(Superclass)

超类是继承的类。Circle的超类是Shape,Shape的超类是NSObject。

The superclass is the class you’re inheriting from. The superclass of Circleis Shape. The superclass of Shape is NSObject.


父类(Parent Class)

父类是超类的另一种表达方式。Shape是Rectangle的父类。

Parent class is another word for “superclass.” For example, Shape is theparent class of Rectangle.


子类(Subclass)

子类是执行继承的类。CircleShape的子类,Shape是NSObject的子类。

The subclass is the class doing the inheriting. Circle is a subclass of Shape,and Shape is a subclass of NSObject.


孩子类(Child Class)

孩子类是子类的另一种表达形式。CircleShape的孩子类。

Child class is another word for “subclass.” Circle is a child class of Shape.It’s your choice whether to use subclass/superclass or parent class/childclass. You’ll come across both pairs in the real world. In this book, we usesuperclass and subclass, possibly because we’re more nerdy than parental.


重写(Override)

如果要改变方法的实现,就需要重写继承的方法。Circle类有自己的draw方法,因此我们说Circle类重写了draw方法。代码运行时,Objective-C会确保调用的总是重写过的方法。

You override an inherited method when you want to change itsimplementation. Circle has its own draw method, so we say it overridesdraw. Objective-C makes sure that the appropriate class’s implementation ofan overridden method is called when the code runs.




猜你喜欢

转载自blog.csdn.net/qq_33737036/article/details/80989817
今日推荐