Download - Chapter1 Animated
-
8/7/2019 Chapter1 Animated
1/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 1
Chapter 1
Introduction to Object-Oriented
Programming and SoftwareDevelopment
Animated Version
-
8/7/2019 Chapter1 Animated
2/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 2
Objectives
After you have read and studied this chapter, youshould be able to
Name the basic components of object-oriented programming
Differentiate classes and objects.
Differentiate class and instance methods.
Differentiate class and instance data values.
Draw program diagrams using icons for classes and objects
Describe significance of inheritance in object-oriented programs Name and explain the stages of the software lifecycle
-
8/7/2019 Chapter1 Animated
3/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 3
Classes and Objects
Object-oriented programs use objects.
An object is a thing, both tangible and intangible.Account, Vehicle, Employee, etc.
To create an object inside the computer program,we must provide a definition for objectshow theybehave and what kinds of information theymaintain called a class.
An object is called an instance of a class.
-
8/7/2019 Chapter1 Animated
4/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 4
Graphical Representation of a Class
The notation we used here is based on the industry standard notation
called UML, which stands for Unified Modeling Language.
We use a rectangle torepresent a class withits name appearinginside the rectangle.
Example: Account Motorcycle
-
8/7/2019 Chapter1 Animated
5/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 5
Graphical Representation of an Object
We use a rectangle torepresent an object andplace the underlinedname of the objectinside the rectangle.
Example:
SV198 This is an object namedSV198.
-
8/7/2019 Chapter1 Animated
6/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 6
An Object with the Class Name
:
This notation indicatesthe class which theobject is an instance.
This tells an objectSV198 is an instance ofthe BankAccount class.
Example:
SV198 : BankAccount
-
8/7/2019 Chapter1 Animated
7/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 7
Messages and Methods
To instruct a class or an object to perform a task, wesend a message to it.
You can send a message only to the classes and
objects that understand the message you sent to
them. A class or an object must possess a matching method
to be able to handle the received message.
A method defined for a class is called a class method,
and a method defined for an object is called an
instance method.
A value we pass to an object when sending a
message is called an argumentof the message.
-
8/7/2019 Chapter1 Animated
8/19
-
8/7/2019 Chapter1 Animated
9/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 9
Sending a Message and Getting an Answer
current balance
getCurrentBalance()
Ask for the currentbalance of thisparticular account.
SV198 : BankAccount
The current balance ofSV198 is returned.
-
8/7/2019 Chapter1 Animated
10/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 10
Calling a Class Method
maximum speed
MobileRobot
getMaximumSpeed()
Ask for the maximumpossible speed for allMobileRobot objects isreturned.
-
8/7/2019 Chapter1 Animated
11/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 11
Class and Instance Data Values
An object is comprised of data values and methods.
An instance data value is used to maintain information
specific to individual instances. For example, each
BankAccount object maintains its balance.
A class data value is used to maintain information shared
by all instances or aggregate information about the
instances.
For example, minimum balance is the information shared
by all Account objects, whereas the average balance of allBankAccount objects is an aggregate information.
-
8/7/2019 Chapter1 Animated
12/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 12
SV098 : BankAccount SV211 : BankAccountSV129 : BankAccount
Sample Instance Data Value
current balance current balance current balance
908.55 1304.98 354.00
All three BankAccountobjects possess thesame instance datavalue current balance.
The actual dollaramounts are, of course,different.
-
8/7/2019 Chapter1 Animated
13/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 13
Sample Class Data Value
SV098 : BankAccount SV211 : BankAccountSV129 : BankAccount
current balance current balance current balance
908.55 1304.98 354.00
BankAccount
minimum balance
100.00
There is one copy of
minimum balance for
the whole class andshared by all instances.
This line is aninstance-ofrelationship.
-
8/7/2019 Chapter1 Animated
14/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 14
Object Icon with Class Data Value
When the class icon isnot shown, we include
the class data value in
the object icon itself.
SV129 : BankAccount
current balance
908.55
minimum balance100.00
-
8/7/2019 Chapter1 Animated
15/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 15
Inheritance
Inheritance is a mechanism in OOP to design two
or more entities that are different but share many
common features.
Features common to all classes are defined in thesuperclass.
The classes that inherit common features from the
superclass are called subclasses.
We also call the superclass an ancestorand the subclass a
descendant.
-
8/7/2019 Chapter1 Animated
16/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 16
A Sample Inheritance
Here are the superclass Account and itssubclasses Savings and Checking.
Account
Checking Savings
-
8/7/2019 Chapter1 Animated
17/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 17
Inheritance Hierarchy
An example of inheritance hierarchy amongdifferent types of students.
Student
Graduate Undergrad
LawMasters Doctoral Commuting Resident
-
8/7/2019 Chapter1 Animated
18/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 18
Software Engineering
Much like building a skyscraper, we need a
disciplined approach in developing complex
software applications.
Software engineeringis the application of asystematic and disciplined approach to the
development, testing, and maintenance of a
program.
In this class, we will learn how to apply soundsoftware engineering principles when we develop
sample programs.
-
8/7/2019 Chapter1 Animated
19/19
The McGraw-Hill Companies, Inc. Permissionrequired for reproduction or display. 4
th Ed Chapter 1 - 19
Software Life Cycle
The sequence of stages from conception tooperation of a program is called software life
cycle.
Five stages are
Analysis
Design
Coding
Testing
Operation and Maintenance