Top Banner
© M.E. Fayad 2000 -- 2005 SJSU -- CMPE L3-1-S1 OO Concepts Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State University One Washington Square San José, CA 95192-0180 http://www.engr.sjsu.edu/~fayad
21

L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

Dec 19, 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: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CMPE L3-1-S1 OO Concepts

Software System Engineering

Dr. M.E. Fayad, Professor

Computer Engineering Department, Room #283I

College of Engineering

San José State University

One Washington Square

San José, CA 95192-0180

http://www.engr.sjsu.edu/~fayad

Page 2: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S2 OO Concepts

2

Lesson 5:Object-Oriented Concepts

Page 3: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S3 OO Concepts

Lesson Objectives

Objectives

3

Understand OO concepts

Explore OO models

Objects

Classes

Methods

Associations

etc…

Page 4: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S4 OO Concepts

4

Objects

When developing OO application, two basic questions:

– What objects does the application need?

– What are the characteristics of these objects

– What functionality should these objects have?

Page 5: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S5 OO Concepts

5

Classes

Objects are grouped in classes Classes are used to distinguish one type of

object from another A class is a set of objects that share some

common structures and behaviors– Each object is an instance of a class

In an OO system, behavior of an object is defined by its class

Page 6: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S6 OO Concepts

6

Attributes

Attributes are properties of an object

– E.g., color, cost, make, and model of a

car object

Properties represent the state of an

object

Page 7: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S7 OO Concepts

7

Object Behavior (1)

Object behavior is described in procedures,

interfaces or methods

A method is defined for a class and can

access the internal state of an object of that

class to perform some operation

Page 8: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S8 OO Concepts

8

Object Behavior (2)

Behavior denotes the collection of methods that abstractly describes what an object is capable of doing

– Each method defines and describes a particular behavior of an object

Objects take responsibility of their own behavior

– E.g., an employee object knows how to compute its salary

Page 9: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S9 OO Concepts

9

Message (1)

Objects perform operations in response to

messages

Message is different from a subroutine call– Different objects can respond to the same

message in different ways

• e.g., cars, motorcycles, and bicycles will all respond

to a stop message -- but differently

A message has a name

Page 10: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S10 OO Concepts

10

Message (2)

An object understands a message when it

can match the message to a method that

has the same name as the message

Message differs from function

– Function says how to do something

– Message says what to do

Page 11: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S11 OO Concepts

11

Methods vs. Messages

Message is the instruction

Method is the implementation

E.g., making French onion soup– Telling someone to make a Greek Salad is the

message

– The way the Greek Salad is prepared is the

method

– The Greek Salad is the object

Page 12: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S12 OO Concepts

12

Encapsulation

Encapsulation is a form of information hiding An object encapsulates the data and

methods– User cannot see the inside of the object “capsule,”

but can use the object by calling the object’s methods

– No object can operate directly on another object’s data -- Important Point.

Page 13: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S13 OO Concepts

13

Class Hierarchy

An object-oriented system organizes classes into a subclass-superclass hierarchy

– superclass = base class or ABC class

– subclass = derived class or concrete class

At the top of the class hierarchy are the most

general classes and at the bottom are the

most specific

Page 14: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S14 OO Concepts

14

Inheritance

Inheritance allows classes to share and reuse behaviors and attributes

A subclass inherits all of the

properties and methods defined in its

superclass

Page 15: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S15 OO Concepts

15

Dynamic Inheritance

Allows objects to change and evolve over time

Superclasses (or base classes) provide

properties and attributes for objects– Changing superclasses changes the properties

and attributes of a class

Ability to add, delete, or change parents from

objects (or classes) at run time

Page 16: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S16 OO Concepts

16

Multiple Inheritance

A class can inherit its state (attributes) and behaviors from more than one superclass

Example: a utility vehicle inherits

attributes from both the Car and Truck

classes

Page 17: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S17 OO Concepts

17

Polymorphism

The same operation may behave differently on different classes

Example: in a payroll system, manager,

office worker, and production worker are

objects that respond to the compute payroll

message -- but differently

Page 18: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S18 OO Concepts

18

Associations

Association represents the relationship between objects and classes

Associations are bidirectional.

Associations have cardinality.

– How many instances of one class may relate to a

single instance of an associated class

Page 19: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S19 OO Concepts

19

Consumer-Producer Association

Special form of association

– Also known as client-server association or

a use relationship

Viewed as a one-way interaction

– One object requests the service of

another object

Page 20: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S20 OO Concepts

20

Aggregations

All objects, except the most basic ones, are composed of and may contain other objects

E.g., a car object is an aggregation of

engine, seat, wheels, and other

objects

Page 21: L3-1-S1 OO Concepts © M.E. Fayad 2000 -- 2005 SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.

© M.E. Fayad 2000 -- 2005 SJSU -- CmpE M.E. Fayad L3-1-S21 OO Concepts

21

Discussion Questions What are the differences between inheritance and

aggregation?

T/F

– Use relationship is an aggregation.

– Aggregation is a special form of association.

– Dynamic inheritance allows objects to change and evolve over time.

– Encapsulation is a form of information hiding.

– Objects perform operations in response to messages

Define: class, attribute, method, message, signature, association, encapsulation, polymorphism