1.9 UML(Unified Modelling Language) diagrams
The diagram has three portions, with the first designating the name of the class, the second designating the recommended in-stance variables, and the third designating the recommended methods of the class.
The type declarations of variables, parameters, and return values are specified in the appropriate place following a colon, and the visibility of each member is designated on its left, with the “+” symbol for public visibility, the “#” symbol for protected visibility, and the “−” symbol for private visibility.
2.2.2 Polymorphism and Dynamic Dispatch
Liskov Subtitution Principle
CreditCard car = new PredatoryCreditCard(...);
This is a demonstration of what is known as the Liskov Substitution Principle, which states that a variable (or parameter) with a declared type can be assigned an instance from any direct or indirect subclass of that type. Informally, this is a manifestation of the “is a” relationship modeled by inheritance, as a predatory credit card is a credit card (but a credit card is not necessarily predatory).
Dynamic Dispatch
CreditCard car = new PredatoryCreditCard(...);
Java uses a process known as dynamic dispatch, deciding at runtime to call the ver-sion of the method that is most specific to the actual type of the referenced object (not the declared type). So, if the object is a PredatoryCreditCard instance, it will execute the PredatoryCreditCard.charge method, even if the reference variable has a declared type of CreditCard.
However, the instance “car” cannot execute charge or processMonth() methods, because its type is CreditCard.