click below
click below
Normal Size Small Size show me how
OOP - L4
Subtyping and Subclassing
| Question | Answer |
|---|---|
| Also called subtyping | Subtype |
| It is about inheriting functionality independent from the specific implementation. | Subtype |
| Subtyping is _________ by any subtype, which means that if A is a subtype of B, then A is also a subtype of C. | substitutable |
| A very large number fits in a long but not in an int because int has a much smaller maximum value. | Subtyping |
| Developed in 1987 | Substitution Principle |
| Developed by | Barbara Liskov. |
| Liskov Substitution Principles | Preconditions cannot be strengthened in a subtype - Only same or weaker requirements for subtypes |
| Liskov Substitution Principles | Postconditions cannot be weakened in a subtypes - Only same or stronger effects for subtypes. |
| the Substitution Principle is applied for the reference | type(List) and object type (ArrayList) |
| can accept any type which is a subtype of Number. | add() method |
| objects can be added in the collection. | Integer and Double |
| Also called as subclassing. | Subclass |
| Allows to inherit code from a superclass and lets the user extend and add its fields and methods in addition to the superclass fields and methods. | Subclass |
| Factored out repeated codes, write only the differences. | Subclass |