Presentation is loading. Please wait.

Presentation is loading. Please wait.

Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 1 Chapter 1 Object-Oriented.

Similar presentations


Presentation on theme: "Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 1 Chapter 1 Object-Oriented."— Presentation transcript:

1 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 1 Chapter 1 Object-Oriented Design

2 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 2 Objectives F To become familiar with the process of program development (§12.2). F To understand the relationship types: association, aggregation, composition, strong inheritance, and weak inheritance (§12.3). F To declare classes to represent the relationships among the classes (§12.3).

3 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 3 Software Development Process

4 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 4 Requirement Specification A formal process to understand the problem document in detail what the software system needs to do. involves close interaction between users and designers. Most of the examples in this book are simple, and their requirements are clearly stated. In the real world, however, problems are not well defined. You need to study a problem carefully to identify its requirements.

5 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 5 System Analysis Seeks to analyze the business process in terms of data flow, and to identify the system’s input and output. Part of the analysis entails modeling the system’s behavior. The model is intended to capture the essential elements of the system and to define services to the system.

6 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 6 System Design The process of designing the system’s components This phase involves the use of many levels of abstraction to decompose the problem into manageable components, identify classes and interfaces, and establish relationships among the classes and interfaces.

7 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 7 Implementation The process of translating the system design into programs. Separate programs are written for each component and put to work together. This phase requires the use of a programming language like Java. The implementation involves coding, testing, and debugging.

8 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 8 Testing Ensures that the code meets the requirements specification and weeds out bugs. An independent team of software engineers not involved in the design and implementation of the project usually conducts such testing.

9 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 9 Deployment Deployment makes the project available for use. For a Java applet, this means installing it on a Web server; for a Java application, installing it on the client's computer.

10 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 10 Maintenance Maintenance is concerned with changing and improving the product. A software product must continue to perform and improve in a changing environment. This requires periodic upgrades of the product to fix newly discovered bugs and incorporate changes.

11 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 11 Relationships among Classes F Association F Aggregation F Composition F Inheritance

12 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 12 Association Association represents a general binary relationship that describes an activity between two classes. An association is usually represented as a data field in the class.

13 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 13 Translation is not Unique NOTE: If you don’t need to know the courses a student takes or a faculty teaches, the data field coureList in Student or Faculty can be omitted.

14 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 14 Association Between Same Class Association may exist between objects of the same class. For example, a person may have a supervisor.

15 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 15 Aggregation and Composition Aggregation is a special form of association, which represents an ownership relationship between two classes. Aggregation models the has-a relationship. If an object is exclusively owned by an aggregated object, the relationship between the object and its aggregated object is referred to as composition.

16 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 16 Representing Aggregation in Classes An aggregation relationship is usually represented as a data field in the aggregated class.

17 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Dependency F Relationship between two classes where one class (client) uses the other (supplier) 17

18 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Degree of Coupling 18 Coupling increases Dependency, association, aggregation, composition

19 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 19 Inner Classes Translation If Name or Address is used in the Person class only, they can be declared as an inner class in Person. For example, public class Person { private Name name; private Address address;... class Name {... } class Address {... }

20 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 20 Inheritance Inheritance models the is-an-extension-of relationship between two classes.

21 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 21 Weak Inheritance Relationship A weak is-an-extension-of relationship can be represented using interfaces. For example, the weak is-an-extension-of relationship “students are comparable based on their grades” can be represented by implementing the Comparable interface, as follows:

22 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 22 Class Design 1. Identify classes for the system (e.g, Person, Name, Address) 2. Establish relationships among classes (e.g, A borrower is a person who has a loan) 3. Describe attributes and methods in each class (e.g, The Name class has the properties firstName, lastName, their associated get and set methods, and the getFullName method) 4. Implement the classes (coding the classes, often using get ans set method)

23 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 23 Example 12.1 Borrowing Loans Name BorrowerPersonLoanAddress

24 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 24 Example 12.1 Borrowing Loans, cont. The following is a test program that uses the classes Name, Person, Address, Borrower, and Loan. BorrowLoan Run

25 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Example 12.2 The Rational Class F Is a subclass of Number class F A rational number has a numerator (n) and denominator (d) in the form n/d F Cannot have a denominator of 0, but numerator of 0 is fine. F Rational numbers are used in exact computations involving fractions 25

26 Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 26 Example 11.2 The Rational Class RationalRunTestRationalClass


Download ppt "Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 1 Chapter 1 Object-Oriented."

Similar presentations


Ads by Google