Download presentation
Presentation is loading. Please wait.
Published byZoe Morgan Crawford Modified over 9 years ago
1
Object Oriented Design Lecture #4 – Inheritance, Interfaces, Classes Tomasz Pieciukiewicz
2
Agenda Inheritance Parametrized Classes Interfaces Attributes and Methods
3
INHERITANCE
4
Inheritance types disjont (default) overlapping complete incomplete (default)... (ellipsis)
5
Inheritance types Do not put default inheritance information on the diagram Tree OakBirchPine {disjoint, complete} species
6
Single-aspect inheritance Exchange area Pipe diameter Tank volume pressure Equipment type Pump type Tank type Specialization aspect Equipment name manufacturer cost Suction pressure Compression pressure flow Pump Heat exchanger
7
Single-aspect inheritance Equipment name manufacturer cost Suction pressure Compression pressure flow Exchange area Pipe diameter volume pressure Equipment type Suction pressure Compression pressure flow Exchange area Pipe diameter Tank volume pressure Equipment type Equipment name manufacturer cost PumpHeat Exchanger
8
Multi-aspect inheritance Vehicle {overlapping} Wind-powered Vehicle Engine-powered Vehicle Land Vehicle Water Vehicle propulsion terrain {overlapping} Two inheritance aspects: terrain and propulsion
9
Multi-inheritance Name Person Employed Student Employee Salary Student ID
10
Multi-inheritance: problems Vehicle {economy speed is 50% top speed} top_speed economy_speed() AmphibianCarYacht economy_speed() Water vehicleLand vehicle Name conflict: which top_speed attribute should be inherited by the amphibian? Does the economy_speed() method meaning depend on the inheritance path? (O2: mechanism for renaming of inherited properties; Eiffel: conflict treated as an error.)
11
Dynamic Inheritance Person Manager Engineer Salesman Female Male {mandatory} sex « dynamic » profession
12
Abstract Classes Abstract class can not have instances Defines common part of group of classes with similar semantics In UML marked with tagged value {abstract = TRUE} (=TRUE may be omitted) OR by writing the entity’s (class or method) name in italics. Concrete class – can have instances.
13
Abstract Classes Persona {abstract} Person Company Sequence first next Int sequence... implementation Char sequence... implementation
14
Abstract Methods Per-Hour Employee perHour holidaysHour noofHours noofHolidayHours calculateSalary Employee weeklySalary numberofweeks calculateSalary Contract Employee monthlySalary calculateSalary calculateSalary{abstract} Employee {abstract}
15
Abstract Methods Abstract method – specified in abstract class, implemented in subclasses Abstract class may have abstract methods, but does not have to Concrete class has to implement all inherited abstract methods not implemented in any superclass Concrete class can’t have abstract methods
16
PARAMETRIZED CLASSES
17
Parametrized Classes - notation Set Current parametrization parameter Set insert(T) delete(T) T EmployeeSet « bind » template
18
INTERFACES
19
Interfaces dependency Company realization Person {abstract} First name Last name Date of birth Calculate age Employee salary position Change salary IEmployee «interface» + Change salary
20
Interfaces Stereotype > Method specification, no implementation No attributes All methods are public Method implementation in class which realizes the interface Dependency – shows classes that use an interface
21
Interfaces Employee IEmployee Person Company The abstract class and interface were shown as interface definitions. Abstract classes – unlike interfaces – may contain attributes and method implementations
22
CLASS EXTENT
23
Class Extent Current set of all class instances. Implemented as a special data structure attached to the class. Some methods work on instances Some methods work on the class extent
24
Class Extent I set of direct (no sub-classes) instances of the given class II set of instances of the given class (direct and indirect), limited to the attributes specified in the given class III set of instances of the given class (direct and indirect)
25
ATTRIBUTES AND METHODS
26
Attributes Simple Complex Optional [0..1] Repeatable [x..y] Derived (/name) Class attributes Object attributes
27
Methods abstract object class methods
28
Method Overriding Method specification from specialized class overrides specification from general class Related with method polymorphism Requires dynamic binding Supports reuse Employee name... fire()... Manager fire()
29
Binding Process of replacing symbolic identifier (name) for value, address or internal entity identifier May be early or late
30
Early vs Late Binding Early (static) binding: during compilation and consolidation Pros: ◦ better performance, ◦ full static typechecking Cons: ◦ less flexible, ◦ No dynamic app extensions (plug-ins) Late (dynamic) binding: at runtime Pros: ◦ Method overriding ◦ Dynamic app extension (plug-ins) ◦ Rapid development Cons: ◦ Worse performance ◦ Difficult typechecking
31
Late Binding – why bother? Polymorphism Dynamic views Dynamic stored procedures Query languages Object migration Database schema evolution
32
Method overloading Symbol’s semantics depend on the context – e.g. number or type of arguments ◦ move (x,y) and move (x,y,z) ◦ move (int, int) and move (float, float) Some authors (e.g. Cardelli – evangelist of polymorphic types theory) believe that overloading is not a form of polymorphism ◦ All methods implementing an operation should have the same signature
33
QUESTIONS?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.