Lecture 14 Polymorphism and State Patterns

Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition)

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright W. Howden 1 Lecture 15: Generalization, Polymorphism and States
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 2 Generalization • Creation of super and subtype entities • May be program and design classes, concepts, use cases, etc. • For programs, generalization corresponds to class inheritance • Subtypes can modify, add to, and access properties of supertypes
Background image of page 2
Copyright W. Howden 3 Kinds of Generalization • specialization • specification • construction • extension • limitation • combination
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 4 Specialization • Re-defines defined parent properties and methods. Also called refinement. • E.g. User-defined class constructor always calls the supertype constructor, either explicitly or automatically • E.g. Suppose we have a stack class where a message is returned when an item is pushed on the stack • success if pushed, or error if stack is full • change this so stack-is-full warning is returned when stack becomes full, i.e. last item is pushed
Background image of page 4
Copyright W. Howden 5 Specification • Used to specify behavior, but not to define it • Subtype defines the behavior • E.g. ActionListener interface in Java GUI. Specifies behavior (methods) for listener classes which implement ActionListener
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 6 Construction • For the purposes of re-use of methods and data structures • Defining new methods and data structures in terms of inherited ones • Child may have no logical relationship with parent(s) • E.g. Use of Vector to define a stack class
Background image of page 6
Copyright W. Howden 7 Extension • Adding new properties and methods • No modification of parent properties • Similar to construction but has the “is a property” which construction may not have • E.g. adding button declarations to the Dialog class in a new extends class
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 8 Limitation • Override some methods with blank/null methods • Limits access to certain behaviors • May be used with construction to block methods that have no meaning in the subtype • E.g. WindowAdpator class which is a limitation of WindowListener interface
Background image of page 8
Copyright W. Howden 9 Combination • Uses multiple inheritance for two or more applications of generalization • DS Java example MessageDialog extends (i) Dialog implements (ii) ActionListener (i) extension: add buttons, panels (ii) specification: define actionPerformed method()
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Generalization Correctness Rules (From earlier lecture) is-a An instance of a subtype is also an instance of the supertype. e.g. an administrator is a DS user Substitutability Suppose B is a subtype of A. It should be possible to substitute an instance of B any place that requires something of type A. 100% rule
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

Lecture 14 Polymorphism and State Patterns - Lecture 15:...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online