/rant/
So I am learning Java and OOP and need some commmunity input regarding inheritance and interfaces.
Apart from my understanding regarding the topic which I have put below could I ask for 2 things mainly from your thoughts surrounding and your experience with the related principles.
a) Is there something I am missing, judging by my understanding? Because I though interfaces were the poly, in polymorphism.
b) Is it possible to acheive, fully blown polymorphism without having to reference/cast objects.
SO here goes. As simply as possible, this is what I understand about the topic....
Interfaces are basically another way of - breaking the rules of single inheritance. Many classes can impliment and a class can implement multiple interfaces.
By using interfaces, a child class can, both inherit it's parents methods and be forced to implement it's interface methods. Resulting in an easy to extend and maintain inheritance tree etc/code base.
The catch however is, when the child is referenced under the parent, you only have access to the parent methods. To access the interface methods implemented, you will need to cast or create the child under the interface reference type. (partial polymorphism still!)
Interfaces also allow the collection of multiple classes of different families to be collected under the interface type. Such as in an array. To what benefit I am yet to discover.
In my opinion, it is pointless since I still cannot achieve fully blown polymorphism anyways - by just using the parent reference type and still have access to the interface implementations.
So I am learning Java and OOP and need some commmunity input regarding inheritance and interfaces.
Apart from my understanding regarding the topic which I have put below could I ask for 2 things mainly from your thoughts surrounding and your experience with the related principles.
a) Is there something I am missing, judging by my understanding? Because I though interfaces were the poly, in polymorphism.
b) Is it possible to acheive, fully blown polymorphism without having to reference/cast objects.
SO here goes. As simply as possible, this is what I understand about the topic....
Interfaces are basically another way of - breaking the rules of single inheritance. Many classes can impliment and a class can implement multiple interfaces.
By using interfaces, a child class can, both inherit it's parents methods and be forced to implement it's interface methods. Resulting in an easy to extend and maintain inheritance tree etc/code base.
The catch however is, when the child is referenced under the parent, you only have access to the parent methods. To access the interface methods implemented, you will need to cast or create the child under the interface reference type. (partial polymorphism still!)
Interfaces also allow the collection of multiple classes of different families to be collected under the interface type. Such as in an array. To what benefit I am yet to discover.
In my opinion, it is pointless since I still cannot achieve fully blown polymorphism anyways - by just using the parent reference type and still have access to the interface implementations.