Session 8 - COMP6115 - Class and Method Design
Session 8 - COMP6115 - Class and Method Design
SESSION 8
Chapter 8
LEARNING OBJECTIVES
Classes
• Instantiated classes are objects
• Classes are defined with attributes, states & methods
• Classes communicate through messages
Encapsulation & information hiding
• Combine data and operations into a single object
• Reveal only how to make use of an object to other objects
• Key to reusability
Polymorphism & dynamic binding
Inheritance
POLYMORPHISM & DYNAMIC BINDING
Polymorphism
• The ability to take on several different forms
• Same message triggers different methods in different objects
Dynamic binding
• Methods—the specific method used is selected at run time
• Attributes—data type is chosen at run time
• Implementation of dynamic binding is language specific
Decisions made at run time may induce run-time errors
Need to ensure semantic consistency
POLYMORPHISM EXAMPLE
INHERITANCE
Close coupling means that changes in one part of the design may
require changes in another part
Types
• Interaction coupling measured through message passing
• Inheritance coupling deals with the inheritance hierarchy of classes
Minimize interaction coupling by restricting messages (Law of
Demeter)
to itself
edition
ISBN: 978-1-119-55991-7