2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems...

28
2-1 © Prentice Hall, 2007 Chapter 2: Chapter 2: Introduction to Object Introduction to Object Orientation Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A. Hoffer

Transcript of 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems...

Page 1: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

2-1© Prentice Hall, 2007

Chapter 2:Chapter 2:Introduction to Object Introduction to Object

OrientationOrientation

Object-Oriented Systems Analysis and Design

Joey F. George, Dinesh Batra,

Joseph S. Valacich, Jeffrey A. Hoffer

Page 2: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-2© Prentice Hall, 2007

Chapter ObjectivesChapter Objectives

After studying this chapter you should be able to:– Define an object.– Understand the terms class, attribute, and operations.

– Explain generalization, polymorphism, and inheritance.

– Define association.– Describe modeling and the Unified Modeling

Language.

Page 3: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-3© Prentice Hall, 2007

Unified Modeling Language Unified Modeling Language (UML)(UML)

A standard notation for representing object-oriented systems

Boxes represent classes, components, packages, objects– Containing attributes and operations– Provide interfaces to external entities

Lines represent generalization and other relationships

Page 4: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-4© Prentice Hall, 2007

Sample UML Diagram

Page 5: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-5© Prentice Hall, 2007

What Is an Object?What Is an Object?

An entity that encapsulates data and behavior

- Objects are categorized into classes

- Each individual object is an instance of a class

Page 6: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-6© Prentice Hall, 2007

What Is Encapsulation?What Is Encapsulation?

The characteristic of object-orientation in which data and behavior are bundled into a class and hidden from the outside world

Access to the data and behavior is provided and controlled through an object’s interface

Page 7: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-7© Prentice Hall, 2007

What Is a Class?What Is a Class?

• A category of objects that share the same attributes, operations, relationships, and semantics

• All objects are instances of classes

Page 8: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-8© Prentice Hall, 2007

Name

Attributes

Operations

Page 9: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-9© Prentice Hall, 2007

What Is an Attribute?What Is an Attribute?

• Attribute- a named property of a class that describes a range of values that instances of the attribute might hold

• Attributes are the way classes encapsulate data

Page 10: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-10© Prentice Hall, 2007

Attributes are properties containing values

Minus sign indicates these are private (hidden)

Page 11: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-11© Prentice Hall, 2007

What Is an Operation?What Is an Operation?

A behavior of an object

Implemented in classes are methods

Methods are identified and invoked by their signatures, including name, parameters, and return type

Page 12: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-12© Prentice Hall, 2007

Signature has name, parameters, return type

Method implements the behavior

Page 13: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-13© Prentice Hall, 2007

Plus sign indicates these are public (accessible)

Page 14: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-14© Prentice Hall, 2007

What Is Generalization?What Is Generalization?

A relationship between a more general (or parent) class and a more specific (or child) class

The more specific class has additional attributes and operations

Page 15: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-15© Prentice Hall, 2007

What Is Inheritance?What Is Inheritance?

The mechanism by which the more specific class in a generalization relationship includes the attributes and operations of the more general class

Page 16: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-16© Prentice Hall, 2007

Generalization represented by arrows from subclass to superclassSubclasses

inherit all attributes and operations of superclasses

Page 17: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-17© Prentice Hall, 2007

What Is Polymorphism?What Is Polymorphism?

The ability for different classes of objects to respond to identical messages in different ways

Polymorphism = “having many forms”

Different behaviors for the same message

Page 18: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-18© Prentice Hall, 2007

Here, each type of vehicle has its own version of calcPrice()

Page 19: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-19© Prentice Hall, 2007

What Is a Component?What Is a Component?

A replaceable part of a system providing a clearly defined function through a set of interfaces

Group of classes working together toward a common end; a subsystem

Page 20: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-20© Prentice Hall, 2007

What Is an Interface?What Is an Interface?

The mechanism by which users of a component invoke its behaviors and manipulate its properties

The interface is implemented by method signatures

Page 21: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-21© Prentice Hall, 2007

Interfaces are represented as small rectangles

Page 22: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-22© Prentice Hall, 2007

What Is a Package?What Is a Package?

A logical grouping of related analysis or design elements

Group of classes sharing similar characteristics or purposes

Page 23: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-23© Prentice Hall, 2007

Package is to component as folder is to file

Page 24: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-24© Prentice Hall, 2007

What Is an Association?What Is an Association?

A relationship or link between instances of (or objects) of classes

Three types:– Simple associations: no ownership– Aggregations: part-whole relationships where the part

can exist independently of the whole– Compositions: part-whole relationships where the part

and the whole are fully dependent on each other

Page 25: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-25© Prentice Hall, 2007

This is a binary association, showing roles and multiplicities

roles

multiplicities

Page 26: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-26© Prentice Hall, 2007

Systems ModelingSystems Modeling

Systems modeling – creating an abstraction of a system

Abstraction – focusing on the relevant aspects and ignoring other details

UML is a modeling approach, involving these diagrams:– Use-case, sequence, communication, class, object,

activity, state, composite structure, package, component, deployment

Page 27: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-27© Prentice Hall, 2007

UML DiagramsUML Diagrams– Use-case diagram – shows use cases, actors, and

relationships describing user interactions with system– Sequence diagram – shows interactions of objects via

message-passing in time-ordered manner– Communication diagram – similar to sequence diagram, but

without the time-ordering– Class diagram – shows set of classes and relationships

(generalizations and associations)– Object diagram – shows specific instances of a class diagram– Activity diagram – shows flow of activities, or wokflow of

objects

Page 28: 2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.

Chapter 2 2-28© Prentice Hall, 2007

UML Diagrams (cont.)UML Diagrams (cont.)

– State diagram – shows transitioning of an object from state to state in response to events

– Composite structure diagram – shows how a component whole is made up of its parts

– Package diagram – shows logical grouping of analysis or design elements

– Component diagram – shows software components or modules and their relationships

– Deployment diagram – shows configuration of runtime processing nodes and their components