Top Banner
© Wolfgang Pelz 2001-04 Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron
28

© Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04

Introduction

Object-Oriented Methods:Analysis, Design &

Programming

Dr. Wolfgang PelzDr. Yingcai Xiao

The University of Akron

Page 2: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 2

Outline

• OOA

• OOD: UML

• OOP: C++

Page 3: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 3

OOA - OOD - OOPHenderson

Analysis

Design

Implementation

Coad/Nicola

“Baseball Model”

Page 4: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 4

Outline

• Software Development Models

• Object-Oriented Concepts

• Introduction to C

• UML

Page 5: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 5

UML Bibliography

• The Unified Modeling Language User Guide Booch et al, Addison-Wesley

• UML Toolkit Hans-Erik Eriksson et al, Wiley

• UML in a Nutshell Sinan Si Alhir, O’Reilly

Page 6: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 6

General Bibliography

• Design Patterns Erich Gamma et al, Addison-Wesley

• Applying UML and Patterns Craig Larman, Prentice-Hall

• The Practice of Programming Brian Kernighan et al, Addison-Wesley

Page 7: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 7

C++ References• “C++ for Java Programmers”

Mark Allen Weiss, Pearson / Prentice Hall• “C++: How to Program",

Deitel & Deitel, Prentice Hall• "C++ Primer”

Stanley Lippman, Addison-Wesley• "The C++ Programming Language"

Bjarne Stroustrup, Addison-Wesley• "The Annotated C++ Reference Manual“

Bjarne Stroustrup and Margareth Ellis, Addison Wesley

Page 8: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 8

The Spiral Software Cycle

Traditional

Page 9: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 9

The Spiral Software Cycle

Object-Oriented

Page 10: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 10

The Large Picture

• Hardware Engineering: automated mass production of standard components.

• Software Engineering: treat software development as an engineering process.

• CASE : Computer-Aided Software Engineering• CASE Tools: Automation of Software Development• The fundamental software component is an object.• An important goal of OO is code reuse.

Page 11: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 11

The Large Picture

Design Reuse =>

Computer Science

The study of the theoretical foundations of information and computation and their implementation and application in computer systems.

(http://en.wikipedia.org/wiki/Computer_science)

Computer Science = Data + Data Manipulation

Programming = Data Structures + Algorithms

Code Reuse of algorithms and data structures.

Design Patterns

Page 12: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 12

Objects• concepts, concrete or abstract, with meaning

derived from the problem domain “the real world”

• promote an understanding of the problem domain

• provide a basis for implementation

• encapsulation of state (data values) and behavior (operations)

Page 13: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 13

Objects (cont.)• Exhibit behavior by invoking a method in

response to a message

• instances of classes

• an object-oriented program is a collection of autonomous interacting and collaborating objects

Page 14: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 14

Classes

• objects sharing common characteristics

• dictate the behavior of the object

• contain– state: attributes, fields, variables, data member– behavior: functions, methods, function member

• access specifiers

• instantiation

• abstract versus concrete

Page 15: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 15

3 Pillars of Object-Orientation• encapsulation

• inheritance

• polymorphism

Page 16: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 16

Encapsulation• combination of state and behavior

• implementation details are hidden internally

• internal mechanisms can change while public interfaces remain stable

• state may be retrieved using public methods

• behavior consists of methods activated by receipt of messages

Page 17: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 17

Inheritance• organization of classes into a hierarchical

inheritance tree• data and behavior associated with classes higher

in the tree are accessible to those classes lower in the tree

• terminology– ancestor/descendant– superclass/subclass– generalization/specialization

Page 18: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 18

Single Inheritance• classes/objects inherit from only one parent

• no ambiguity due to name clashes

• examples: Java, Smalltalk

Page 19: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 19

Multiple Inheritance• classes/objects may have more than one

parent

• ambiguity (name clashes) can occur

• allows abstract classes to be more specific in characteristics (kitchen sink problem)

• examples: C++, Eiffel

Page 20: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 20

Inheritance Diagram

Page 21: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 21

Another Inheritance Diagram

Page 22: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 22

Inheritance for Teaching Assistant

• birthday

• library privileges

Page 23: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 23

Polymorphism• polymorphism: many forms

• localizes responsibility for behavior

• object automatically uses correct implementation for a method

• many objects can respond to the same message

• minimizes interface parameter passing

Page 24: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 24

Polymorphism• determination of method is done at:

– run-time: dynamic binding, late binding– compile-time: static binding, early binding

• treat many types (all derived from the same type) as if they were all one type

• single piece of interface works on all these types

Page 25: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 25

Polymorphism Example

Page 26: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 26

3 Pillars of Object-Orientation• Encapsulation

Combine data structures and algorithm together and insulate internal code and data from their interface. Easily to be reused.

• InheritanceReuse the code of the parents as is.

• PolymorphismObjects of similar type have the same interface. Easily to be reused.

Page 27: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 27

Relationships• is-a: code reuse through inheritance

– instances of a subclass must be more specialized forms of the superclass

– instances of a subclass can be used where quantities of the superclass are expected

• has-a: code reuse through inclusion – component or contains– instances of a class possess fields of a given

type

Page 28: © Wolfgang Pelz 2001-04Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.

© Wolfgang Pelz 2001-04Introduction 28

OOA: Objects & Methods• write description of problem domain• nouns are candidates for objects• verbs are candidates for methods• designs are implementation-language independent• UML can be used to depict the designs