This commit is contained in:
2020-05-24 19:13:09 +02:00
parent a0bdd99b3f
commit 608dafaf85
3 changed files with 63 additions and 8 deletions

View File

@ -1,12 +1,6 @@
# Inheritance, Properties and Polymorphism
# Inheritance and Polymorphism
Rust does not allow extending classes. Instead the base class is stored as a
field in the extending class. Polymorphism can then be achieved by passing the
field instead of the whole object to a function. Although casting back to the
advanced class or overriding functions is not possible.
Properties don't exist either, like in java. But replacing them with getters and
setters is also discouraged. Quoting from a reddit post 'Expose behavior, not
state'. That means you should present functions to outside viewers and not your
plain data. An object should be able to do all its intended functions itself
without having an outside observer read its data.