Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling.

Slides:



Advertisements
Similar presentations
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Ch 12: Object-Oriented Analysis
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.
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Introduction To System Analysis and Design
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
Copyright 2004 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Second Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix.
1 CS1001 Lecture Overview Object Oriented Design Object Oriented Design.
Unified Modeling Language
Introduction To System Analysis and design
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.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
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.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Copyright 2001 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix A Object-Oriented.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
Unified Modeling Language, Version 2.0
Introduction To System Analysis and Design
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.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Introduction to OOAD and the UML
Chapter 5 Programming with Objects and Classes OO Programming Concepts OO Programming Concepts Declaring and Creating Objects Declaring and Creating Objects.
Chapter 17 – Object- Oriented Design. Chapter Goals To learn about the software life cycle To learn about the software life cycle To learn how to discover.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
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.
1 Unified Modeling Language, Version 2.0 Chapter 2.
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.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
Basic Characteristics of Object-Oriented Systems
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Fall 2013 Chapter 10 Thinking.
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 14 Slide 1 Object-Oriented Design.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
Chapter 13 Abstract Classes and Interfaces
Chapter 10 Thinking in Objects
The Movement To Objects
Chapter 10 Thinking in Objects
Object-Oriented Analysis and Design
Chapter 10 Thinking in Objects
Systems Analysis and Design With UML 2
Chapter 11 Object-Oriented Design
Unified Modeling Language
Chapter 10 Object-Oriented Modeling
Reference: COS240 Syllabus
Chapter 2 Elementary Programming
Chapter 9 Thinking in Objects
Chapter 20 Object-Oriented Analysis and Design
Chapter 9 Thinking in Objects
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
UML  UML stands for Unified Modeling Language. It is a standard which is mainly used for creating object- oriented, meaningful documentation models for.
Presentation transcript:

Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling

Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives To become familiar with the process of program development (§10.2). To the relationship types: association, aggregation, composition, strong inheritance, and weak inheritance (§10.3). To declare classes to represent the relationships among the classes (§10.3). To design systems by identifying the classes and discovering the relationships among these classes (§10.4). To implement the Rational class and process rational numbers using this class (§10.5). To design classes that follow the class-design guidelines (§10.6). To model dynamic behavior using sequence diagrams and statechart diagrams (§10.7 Optional) To know the concept of framework-based programming using Java API (§10.8).

Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Software Development Process

Liang,Introduction to Java Programming,revised by Dai-kaiyu 4 Requirement Specification A formal process that seeks to understand the problem and document in detail what the software system needs to do. This phase 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 11 UML- Use-Case Describe system behavior and show how to capture it in a model.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 12 UML- Use-Case

Liang,Introduction to Java Programming,revised by Dai-kaiyu 13 UML-Activity Diagram It is essentially a flow chart, showing flow of control from activity to activity.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 14 UML-Class Diagrams Describe the static view of the system and show how to capture it in a model.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 15 Sequence diagrams Sequence diagrams describe interactions among objects by depicting the time ordering of method invocations. The diagram shows: The objects participating in the interaction. The sequence of messages exchanged.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 16 Sequence diagrams, cont.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 17 UML-Collaboration Diagram

Liang,Introduction to Java Programming,revised by Dai-kaiyu 18 UML-Collaboration Diagram

Liang,Introduction to Java Programming,revised by Dai-kaiyu 19 Statechart diagrams Statechart diagrams describe flow of control of the object.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 20 Statechart diagrams, cont.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 21 UML- Component Diagram A diagram that shows the organization of and the dependencies among a set of components.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 22 UML-Deployment Diagram  The deployment diagram shows:  Configuration of processing nodes at run-time  Communication links between these nodes  Component instances and objects that reside on them

Liang,Introduction to Java Programming,revised by Dai-kaiyu 23 Relationships among Classes Association Aggregation Composition Inheritance

Liang,Introduction to Java Programming,revised by Dai-kaiyu 24 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 25 Association Between Same Class Association may exist between objects of the same class. For example, a person may have a supervisor.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 26 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.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 27 Representing Aggregation in Classes An aggregation relationship is usually represented as a data field in the aggregated class.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 28 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 {... }

Liang,Introduction to Java Programming,revised by Dai-kaiyu 29 Inheritance Inheritance models the is-an-extension-of relationship between two classes.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 30 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:

Liang,Introduction to Java Programming,revised by Dai-kaiyu 31 Class Design 1. Identify classes for the system. 2. Describe attributes and methods in each class. 3. Establish relationships among classes. 4. Create classes.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 32 Example 10.1 Borrowing Loans Name BorrowerPersonLoanAddress

Liang,Introduction to Java Programming,revised by Dai-kaiyu 33 Example 10.1 Borrowing Loans, cont. The following is a test program that uses the classes Name, Person, Address, Borrower, and Loan. BorrowLoan Run

Liang,Introduction to Java Programming,revised by Dai-kaiyu 34 Example 10.2 The Rational Class RationalRunTestRationalClass

Liang,Introduction to Java Programming,revised by Dai-kaiyu 35 Class Design Guidelines Designing a Single Class. Using Modifiers public, protected, private and static Using Inheritance or Aggregation Using Interfaces or Abstract Classes

Liang,Introduction to Java Programming,revised by Dai-kaiyu 36 Designing a Class A class should describe a single entity or a set of similar operations. A single entity with too many responsibilities can be broken into several classes to separate responsibilities.  The String class, StringBuffer class, and StringTokenizer class all deal with strings, for example, but have different responsibilities. System.Text.StringBuilder in jdk5.0

Liang,Introduction to Java Programming,revised by Dai-kaiyu 37 Designing a Class, cont. Classes are usually designed for use by many different customers. To make a class useful in a wide range of applications, the class should provide a variety of ways for customization through properties and methods. Provide a public no-arg constructor and override the equals method and the toString method defined in the Object class whenever possible.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 38 Designing a Class, cont. Follow standard Java programming style and naming conventions. Choose informative names for classes, data fields, and methods. Always place the data declaration before the constructor, and place constructors before methods. Always provide a constructor and initialize variables to avoid programming errors.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 39 Using Visibility Modifiers Each class can present two contracts – one for the users of the class and one for the extenders of the class. Make the fields private and accessor methods public if they are intended for the users of the class. Make the fields or method protected if they are intended for extenders of the class. A class should also hide methods not intended for client use but only for internal use within the class.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 40 Using the static Modifier A property that is shared by all the instances of the class should be declared as a static property. A method that is not dependent on a specific instance should be declared as a static method

Liang,Introduction to Java Programming,revised by Dai-kaiyu 41 Using Inheritance or Composition, cont. public class Cylinder { private Circle circle; /** Constructors */ /** Methods */ } If polymorphism is desirable, you need to use the inheritance design. If you don’t care about polymorphism, the aggregation design gives more flexibility because the classes are less dependent using aggregation than using inheritance. public class Cylinder extends Circle{ /** Constructors */ /** Methods */ }

Liang,Introduction to Java Programming,revised by Dai-kaiyu 42 Using Interfaces or Abstract Classes Both interfaces and abstract classes can be used to generalize common features.  a strong is-an-extension-of relationship that clearly describes a parent-child relationship should be modeled using classes. since an orange is a fruit, their relationship should be modeled using class inheritance.  A weak is-an-extension-of relationship can be modeled using interfaces all strings are comparable, so the String class implements the Comparable interface

Liang,Introduction to Java Programming,revised by Dai-kaiyu 43 Using Interfaces or Abstract Classes, cont. Interfaces are more flexible than abstract classes  because a subclass can extend only one superclass, but implement any number of interfaces.  However, interfaces cannot contain concrete methods. You can combine the virtues of interfaces and abstract classes by creating an interface with a companion abstract class that implements the interface. So you can use the interface or its companion class whichever is more convenient.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 44 Supplement P: Designing Generic Matrix Classes Objective: This example gives a generic class for matrix arithmetic. This class implements matrix addition and multiplication common for all types of matrices. GenericMatrix

Liang,Introduction to Java Programming,revised by Dai-kaiyu 45 Example 10.3, cont.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 46 Example 10.3, cont. Objective: This example gives two programs that utilize the GenericMatrix class for integer matrix arithmetic and rational matrix arithmetic. TestIntegerMatrix Run TestRationalMatrix Run RationalMatrix IntegerMatrix

Liang,Introduction to Java Programming,revised by Dai-kaiyu 47 Framework-Based Programming The classes and interfaces in the Java API establish a framework for programmers to develop applications using Java. You have to use these classes and interfaces and follow their conventions and rules to create applications. This is referred to as framework-based programming. Once you understand the concept of Java and object- orient programming, the most important lesson from now on is learning how to use the API to develop useful programs.

Liang,Introduction to Java Programming,revised by Dai-kaiyu 48 Framework-Based Programming, cont. the framework-based programming using the Java API in our course  Java GUI programming framework in Chapters 11, 12, 13, and 14,  the Java exception handling framework in Chapter 15  the Java IO framework in Chapter 16