Object-Oriented Design Lecture 9: Generalization/Specialization - - PowerPoint PPT Presentation

object oriented design
SMART_READER_LITE
LIVE PREVIEW

Object-Oriented Design Lecture 9: Generalization/Specialization - - PowerPoint PPT Presentation

Object-Oriented Design Lecture 9: Generalization/Specialization Sharif University of Technology 1 Department of Computer Engineering Analysis Workflow: Analyze a Use Case The analysis workflow consists of the following activities:


slide-1
SLIDE 1

Department of Computer Engineering

Object-Oriented Design

Lecture 9: Generalization/Specialization

Sharif University of Technology 1

slide-2
SLIDE 2

Analysis Workflow: Analyze a Use Case

  • The analysis workflow consists of the following

activities:

  • Architectural analysis
  • Analyze a use case
  • Outputs:
  • analysis classes
  • use case realizations
  • Analyze a class
  • Analyze a package

Sharif University of Technology 2

slide-3
SLIDE 3

Generalization

  • Generalization is a relationship between a more general

thing and a more specific thing:

  • the more specific thing is consistent in every way with the more

general thing.

  • the substitutability principle states that you can substitute the

more specific thing anywhere the more general thing is expected.

  • generalization applies to all classifiers and some other modeling

elements.

Sharif University of Technology 3

slide-4
SLIDE 4

Generalization/Specialization

  • Generalization hierarchies may be created by generalizing

from specific things or by specializing from general things.

Sharif University of Technology 4

slide-5
SLIDE 5

Inheritance

  • Class inheritance is implicit in a generalization relationship between

classes.

  • The subclass inherits the following features from its parents - attributes,
  • perations, relationships, and constraints.

Sharif University of Technology 5

slide-6
SLIDE 6

Inheritance: Overriding

  • Subclasses may:
  • add new features;
  • override inherited operations:
  • the subclass provides a new operation with exactly the same

signature as the parent operation it wishes to override; the operation signature consists of an operation name, types of all parameters in

  • rder, and return type.

Sharif University of Technology 6

slide-7
SLIDE 7

Abstract Operations and Classes

  • Abstract operations are designed to have no implementation:
  • they serve as placeholders;
  • all concrete subclasses must implement all inherited abstract operations.
  • An abstract class has one or more abstract operations:
  • abstract classes can't be instantiated;
  • abstract classes define a contract as a set of abstract operations that

concrete subclasses must implement.

Sharif University of Technology 7

slide-8
SLIDE 8

Abstraction Level

  • all things at the same level in a generalization hierarchy

should be at the same level of abstraction.

Sharif University of Technology 8

slide-9
SLIDE 9

Polymorphism

  • Polymorphism means "many forms". It allows you to design systems using

an abstract class, then substitute concrete subclasses at runtime - such systems are very flexible and easy to extend; just add more subclasses.

  • Encapsulation, inheritance, and polymorphism are the "three pillars" of

OO.

Sharif University of Technology 9

slide-10
SLIDE 10

Polymorphism: Example

Sharif University of Technology 10

slide-11
SLIDE 11

Polymorphism: Concrete Operations

  • Polymorphic operations have more than one implementation:
  • different classes may implement the same polymorphic (abstract/concrete)
  • peration differently;
  • polymorphism allows instances of different classes to respond to the same

message in different ways.

Sharif University of Technology 11

slide-12
SLIDE 12

Advanced Generalization: Generalization Sets

  • Generalization set - a set of subclasses organized according to a particular rule;

constraints:

  • {complete} - generalization set contains all possible members;
  • {incomplete} - generalization set does not contain all possible members;
  • {disjoint} - an object may be an instance of no more than one of the members
  • f the generalization set;
  • {overlapping} - an object may be an instance of more than one of the members
  • f the generalization set;
  • {incomplete, disjoint} - the default.

Sharif University of Technology 12

slide-13
SLIDE 13

Generalization Sets: Implementation

Sharif University of Technology 13

slide-14
SLIDE 14

Generalization Sets: Example

Sharif University of Technology 14

slide-15
SLIDE 15

Reference

  • Arlow, J., Neustadt, I., UML 2 and the Unified Process: Practical Object-

Oriented Analysis and Design, 2nd Ed. Addison-Wesley, 2005.

Sharif University of Technology 15