Suppose I have a parent class that implements a protocol:
@interface GameViewController : UIViewController<GamePrizeDelegate> {
...
}
And then I make subclasses of it:
@interface TennisViewController : GameViewController {
...
}
@interface SoccerViewController : GameViewController {
...
}
Do I have to include the GamePrizeDelegate
also in the subclasses? Are the protocols inherited as well?
Thanks!
It's more code, but there just isn't multiple inheritance as a language feature in objective-C. Composition is very often a better approach to take than inheritance, especially if you do much unit testing on the code.
Inheritance allows us to define a class in terms of another class which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.
I think No. Inheritance concept is to inherit properties from one class to another but not vice versa. But since parent class reference variable points to sub class objects. So it is possible to access child class properties by parent class object if only the down casting is allowed or possible....
Subclass can not access parent private properties (fields) and methods. It can access public , protected and default properties and methods only. thank you !
Referring to Apple's documentation: Your subclass does inherit the adoption of the protocol, so you don't have to adopt it again.
Conforming to a Protocol
A class is said to conform to a formal protocol if it adopts the protocol or inherits from another class that adopts it. An instance of a class is said to conform to the same set of protocols its class conforms to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With