+ 2
What is subtyping in cpp
3 Réponses
+ 2
Subtyping is a method for substitution and code reuse used in object-oriented programming languages to prevent unnecessary copying of largely similar code and promote code readability and prevent bugs.
From Internet.
Hope it helps!
Happy Coding 🤠
+ 2
Is it same as inheritance?
+ 1
Both are similar, but not the same.
Subtyping means writing a class B which conforms to A's interface, as well as possibly adding some new methods of its own. Per Liskov's substitution principle1, in any context where an A is expected we can supply a B instead.
Inheritance means writing a class B that specialises A to a particular use, by reusing some of its behaviour and perhaps overriding parts.
It is further explained here, you can check it out.
https://counterexamples.org/subtyping-vs-inheritance.html