DSchap01
-
Upload
muhammad-hashim -
Category
Documents
-
view
218 -
download
0
Transcript of DSchap01
-
8/3/2019 DSchap01
1/32
IAS1223 DATA STRUCTURES AND ALGORITHMS
Chapter 1
Software Engineering
Principles and Java Classes
1
-
8/3/2019 DSchap01
2/32
Chapter Objectives
Data Structures Using Java
2
Learn about software engineering principles
Discover what an algorithm is and explore problem-
solving techniques
Become aware of structured design and object-
oriented design programming methodologies
Learn about user-defined classes
Learn about private, protected, and public membersof a class
-
8/3/2019 DSchap01
3/32
Chapter Objectives
Data Structures Using Java
3
Explore how classes are implemented
Become aware of Unified Modeling Language (UML)
notation
Examine constructors and destructors
Learn about the abstract data type (ADT)
Explore how classes are used to implement ADT
-
8/3/2019 DSchap01
4/32
Software Life Cycle
Data Structures Using Java
4
Life cycle: the many phases a program goes through
from the time it is conceived until the time it is
retired
Three fundamental stages of a program
Development
Use
Maintenance
-
8/3/2019 DSchap01
5/32
-
8/3/2019 DSchap01
6/32
Software Development Phase
Data Structures Using Java
6
Design
Algorithm
Structured design
Divide problem into subproblems and analyze eachsubproblem
Object-oriented design Identify components (objects) which form the basis of solution
Determine how these objects interact with one another
-
8/3/2019 DSchap01
7/32
Software Development Phase
Data Structures Using Java
7
Three basic principles of object-oriented design
(OOD)
Encapsulation: ability to combine data and operations
in a single unit
Inheritance: ability to create new data types from
existing data types
Polymorphism: ability to use the same expression to
denote different operations
-
8/3/2019 DSchap01
8/32
Software Development Phase
Data Structures Using Java
8
Implementation
Write and compile programming code to implement
classes and functions discovered in design phase
Precondition: a statement specifying that condition(s)
that must be true before the method is called.
Postcondition: a statement specifying what is true after
the method call is completed.
-
8/3/2019 DSchap01
9/32
Software Development Phase
Data Structures Using Java
9
Testing and Debugging
Test the correctness of the program to make sure it doeswhat it is supposed to do
Find and fix errors Run program through series of specific tests, test cases
-
8/3/2019 DSchap01
10/32
Software Development Phase
Data Structures Using Java
10
Testing and Debugging
Black-box testing: test based on inputs and outputs not
the internal working of the algorithm or function
White-box testing: relies on the internal structure and
implementation of a function or algorithm; ensures that
every part of the function or algorithm executes at least
once
-
8/3/2019 DSchap01
11/32
Classes
Data Structures Using Java
11
class: reserved word; collection of a fixed numberof components
Components: member of a class
Members accessed by name Class categories/modifiers
Private
Protected
public
-
8/3/2019 DSchap01
12/32
Classes
Data Structures Using Java
12
private: members of class not accessible outside
class
public: members of class accessible outside class
Class members: can be methods or variables
Variable members declared like any other
variables
-
8/3/2019 DSchap01
13/32
Syntax
Data Structures Using Java
13
General syntax for defining a class:modifier(s) class ClassIdentifier modifier(s)
{
classMembers}
General syntax for using the operator new:new className()
ornew className(argument1, argument2, ..., argumentN)
-
8/3/2019 DSchap01
14/32
Classes
Data Structures Using Java
14
Syntax to access data member of class object or
method:
referenceVariableName.memberName
Shallow copying: two or more reference variables of
the same type point to the same object
Deep copying: each reference variable refers to its
own object. Use method makeCopy()
-
8/3/2019 DSchap01
15/32
Constructors
Data Structures Using Java
15
Guarantee that data members are initialized when
object is declared
Automatically execute when class object created
Name of constructor is name of class
More than one constructor can be present in one class
Default constructor: constructor without parameters
-
8/3/2019 DSchap01
16/32
The Copy Constructor
Data Structures Using Java
16
Executes when an object is instantiated
Initialized using an existing object
S
yntaxpublic ClassName(ClassName otherObject)
-
8/3/2019 DSchap01
17/32
UML Diagram
Data Structures Using Java
17
-
8/3/2019 DSchap01
18/32
UML Diagram
Data Structures Using Java
18
Top box: Name of class
Middle box: data members and their data types
Bottom box: member methods names, parameter
list, return type of method + means public method
- means private method
# means protected method
-
8/3/2019 DSchap01
19/32
Example: class Clock
Data Structures Using Java
19
myClock = new Clock();
yourClock = new Clock(9,35,15);
-
8/3/2019 DSchap01
20/32
-
8/3/2019 DSchap01
21/32
Example: class Clock
Data Structures Using Java
21
-
8/3/2019 DSchap01
22/32
-
8/3/2019 DSchap01
23/32
The Modifier Static
Data Structures Using Java
23
In method heading, specifies that method can beinvoked by using name of class
If used to declare data member, data member
invoked by using class name Static data members of class exist even when no
object of class type instantiated
Static variables are initialized to their default
values
-
8/3/2019 DSchap01
24/32
static Data Members of a Class
Data Structures Using Java
24
Illustrate illusObject1 = new Illustrate(3);
Illustrate illusObject2 = new Illustrate(5);
-
8/3/2019 DSchap01
25/32
Finalizers
Data Structures Using Java
25
Automatically execute when class object goes out of
scope
Have no parameters
Only one finalizer per class
Name of finalizer: finalize
-
8/3/2019 DSchap01
26/32
Creating Packages
Data Structures Using Java
26
Can create packages using reserved word package
Define the class to be public (If class not public it can
only be used within package)
Choose name for package. Organize package (createsubdirectories)
-
8/3/2019 DSchap01
27/32
The Reference this
Data Structures Using Java
27
Refers to instance variables and methods of a class
Used to implement cascaded method calls
-
8/3/2019 DSchap01
28/32
Inner Classes
Data Structures Using Java
28
Defined within other classes
Can be either a complete class definition or
anonymous inner class definition
Used to handle events
-
8/3/2019 DSchap01
29/32
-
8/3/2019 DSchap01
30/32
Object-Oriented Design
Data Structures Using Java
30
Simplified methodology
1. Write down detailed description of problem
2. Identify all (relevant) nouns and verbs
3. From list of nouns, select objects
4. Identify data components of each object
5. From list of verbs, select operations
-
8/3/2019 DSchap01
31/32
Chapter Summary
Data Structures Using Java
31
Software Life Cycle
Development, Use, Maintenance
Algorithm Analysis: The Big-O Notation
Classes
UML Diagram
Constructors, Destructors
Abstract Data Types
-
8/3/2019 DSchap01
32/32
Chapter Summary
Data Structures Using Java
32
Software Development Phase
Analysis
Design
Structured design
Object-oriented design
Encapsulation, Inheritance, Polymorphism
Implementation
Testing and Debugging