Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.

Slides:



Advertisements
Similar presentations
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L11 (Chapter 20) Lists, Stacks,
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Chapter 4 Linked Structures. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 4-2 Chapter Objectives Describe the use of references to create.
Inheritance and interfaces A class C1 is derived from class C2, then C1 is called subclass, and C2 is called superclass Superclass-parent, base class Subclass.
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
Chapter 19 Java Data Structures
Chapter 11 Abstract Classes and Interfaces 1. Abstract method New modifier for class and method: abstract An abstract method has no body Compare: abstract.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 10 Thinking in Objects.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Announcements  I will discuss the labtest and the written test #2 common mistakes, solution, etc. in the next class  not today as I am still waiting.
Chapter 7 Arrays and Vectors Introducing Arrays Introducing Arrays Declaring Arrays, Creating Arrays, and Initializing Arrays Declaring Arrays, Creating.
1 Chapter 10 Object-Oriented Thinking. 2 Class Abstraction and Encapsulation Class abstraction means to separate class implementation details from the.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 20 Lists, Stacks,
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Chapter 18 Java Collections Framework
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
Chapter 6 Object-Oriented Design. © 2004 Pearson Addison-Wesley. All rights reserved6-2 Object-Oriented Design Now we can extend our discussion of the.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
Chapter 5 Programming with Objects and Classes OO Programming Concepts OO Programming Concepts Declaring and Creating Objects Declaring and Creating Objects.
Inheritance and Access Control CS 162 (Summer 2009)
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 19 Generics.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 1 Chapter 13 Abstract Classes and Interfaces.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 12 Inheritance and Class Design 1.
1 Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 10 More on Objects and Classes.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Chapter 15 Abstract Classes and Interfaces.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 10 Thinking in Objects.
CS202 Java Object Oriented Programming Introduction to Collection Classes Chengyu Sun California State University, Los Angeles.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Lecture 5:Interfaces and Abstract Classes
Chapter 13 Abstract Classes and Interfaces
Chapter 19 Java Data Structures
Chapter 11 Object-Oriented Design
Chapter 10 Object-Oriented Modeling
Chapter 10 Thinking in Objects
Chapter 17 Object-Oriented Data Structures
Chapter 10 Thinking in Objects
Introduction to Data Structure
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Chapter 19 Generics.
Chapter 10 Thinking in Objects
Presentation transcript:

Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines F Wrapper Classes F Generic Sort Class F Generic Matrix Class F Generic Linked List Class

Software Development Process

Relationships among Classes F Association F Aggregation F Inheritance

Association Association represents a general binary relationship that describes an activity between two classes.

Association, cont. An association is usually represented as a data field in the class. public class Course { private Faculty faculty; /**Constructors*/ /**Methods*/ }

Aggregation Aggregation is a special form of association, which represents an ownership relationship between two classes. Aggregation models the relationship like has-a, part-of, owns, and employed-by.

Inheritance Inheritance models the is-a relationship between two classes.

Inheritance public class Student extend Person { /**Constructors*/ /**Methods*/ } public class Faculty extend Person { /**Constructors*/ /**Methods*/ }

Class Development 1. Identify classes for the system. 2. Describe attributes and methods in each class. 3. Establish relationships among classes. 4. Create classes.

Example 9.1 Borrowing Mortgages Name BorrowerPersonMortgageAddress

Example 9.1 Borrowing Mortgages, cont. The following is a test program that uses the classes Name, Person, Address, Borrower, and Mortgage. BorrowMortgage Run

Example 9.2 The Rational Class RationalRunTestRationalClass

Class Design Guidelines F Hide private data and private methods. F A property that is shared by all the instances of the class should be declared as a class property. F Provide a public default constructor and override the equals method and the toString method defined in the Object class whenever possible.

Class Design Guidelines, cont. F Choose informative names and follow consistent styles. F A class should describe a single entity or a set of similar operations. F Group common data fields and operations shared by other classes.

Wrapper Classes F Boolean F Character F Short F Byte F Integer F Long F Float F Double

The Integer Class and The Double Class F Constructors  Class Constants MAX_VALUE, MIN_VALUE F Conversion Methods

Example 9.3 Sorting an Array of Objects Objective: The example presents a generic method for sorting an array of objects. The objects are instances of the Comparable interface and they are compared using the compareTo method. Generic Sort Run

Example 9.4 Designing Generic Classes F Objective: This example gives a generic class for matrix arithmetic. This class implements matrix addition and multiplication common for all types of matrices. GenericMatrix

Example 9.4, cont.

F Objective: This example gives two programs that utilize the GenericMatrix class for integer matrix arithmetic and rational matrix arithmetic. TestIntegerMatrix Run TestRationalMatrix Run Rational Matrix IntegerMatrix

Linked List Arrays are useful for storing and managing a set of elements of the same type. However, since the length of an array is fixed once the array is created, you need to know the length of the array before you create it. A linked list can grow or shrink dynamically as needed. A linked list consists of nodes, as shown in Figure Each node contains an element and each node is linked to its next neighbor. Thus, a node can be defined as a class as follows:

Linked List Structure public class Node { Object element; Node next; public Node(Object o) { element = o; }

Create a Linked List with three Nodes Node n1 = new Node(new String(“Welcome to Java!”)); Node n2 = new Node(new JButton(“OK”)); Node n3 = new Node(new Rational(1, 2)); n1.next = n2; n2.next = n3; Node first = n1; Node last = n3;

Generic Linked List Add a new node

Generic Linked List Remove a new node

Example 9.5 Using Linked List F This example creates a linked list using GenericLinkedList. It then uses the add method to add strings to the list and uses the remove method to remove strings from the list. GenericLinkedList Run TestLinkedList

Generic Linked List GenericLinkedList list = new GenericLinkedList(); list.addLast(new String(“Welcome to Java”)); list.addLast(new JButton(“OK”)); list.addLast(new Rational(1, 2));