Professional Documents
Culture Documents
Chapter Objectives
2
Learn about software engineering principles Discover what an algorithm is and explore problemsolving techniques Become aware of structured design and objectoriented design programming methodologies Learn about user-defined classes Learn about private, protected, and public members of a class
Chapter Objectives
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
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
Analysis
Understand
problem Requirements analysis Data analysis Divide problem into subproblems and perform analysis
Design
Algorithm Structured
design design
Object-oriented
Identify components (objects) which form the basis of solution Determine how these objects interact with one another
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
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.
the correctness of the program to make sure it does what it is supposed to do Find and fix errors Run program through series of specific tests, test cases
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
Classes
11
class: reserved word; collection of a fixed number of components Components: member of a class Members accessed by name Class categories/modifiers
Private Protected public
Classes
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
Syntax
13
Classes
14
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()
Constructors
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
Executes when an object is instantiated Initialized using an existing object Syntax public ClassName(ClassName otherObject)
UML Diagram
17
UML Diagram
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
Public value-returning method Takes no parameters Returns address of String object Output using print and println methods Default definition creates String with name of objects class name followed by hash code of object
In method heading, specifies that method can be invoked 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
Finalizers
25
Automatically execute when class object goes out of scope Have no parameters Only one finalizer per class Name of finalizer: finalize
Creating Packages
26
the class to be public (If class not public it can only be used within package) Choose name for package. Organize package (create subdirectories)
Refers to instance variables and methods of a class Used to implement cascaded method calls
Inner Classes
28
Defined within other classes Can be either a complete class definition or anonymous inner class definition Used to handle events
Definition: A data type that specifies the logical properties without the implementation details
Object-Oriented Design
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
Chapter Summary
31
Use, Maintenance
Algorithm Analysis: The Big-O Notation Classes UML Diagram Constructors, Destructors Abstract Data Types
Chapter Summary
32
Implementation Testing
and Debugging