CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
1 Object-oriented design Part 2: OO tools & UML. 2 CRC cards Design tool & method for discovering classes, responsibilities, & relationships Record on.
Advertisements

COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms.
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
UML Class and Sequence Diagrams Violet Slides adapted from Marty Stepp, CSE 403, Winter 2012 CSE 403 Spring 2012 Anton Osobov.
Ch 12: Object-Oriented Analysis
Improved software quality through semantic descriptions (Skutt) Karlstad University Dept. of Computer Science UML introduction A short introduction.
Class Relationships. In systems with multiple classes, it can become difficult to keep track of relationships  e.g. the Student class requires the Course.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
1 Object-Oriented Modeling Using UML CS 3331 Fall 2009.
Object-oriented design Part 4: More UML. Interfaces An interface is a language construct specific to Java Java does not support multiple inheritance Interfaces.
1 Lab Beginning Analysis and Design 4 Completion of first version of use case diagram initiates the processes of analysis and design. 4 UML provides.
The Unified Modeling Language (UML) Class Diagrams.
Chapter 2 (Horstmann’s Book) – Part 2 The Object-Oriented Design Process Hwajung Lee.
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
Object-Oriented Design & Patterns Cay S
CS 151: Object-Oriented Design September 3 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
CS 160: Software Engineering October 8 Class Meeting
COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms.
CS 160: Software Engineering September 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
11 Partnership for Performance How to hear this lecture Click on the icon: to hear the narration for each slide.
CS 46B: Introduction to Data Structures June 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Classes CS 21a: Introduction to Computing I First Semester,
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 12 – Object-Oriented Design.
Systems Analysis & Design 7 th Edition Chapter 5.
CS 151: Object-Oriented Design October 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
Fall 2010 CS4310 Requirements Engineering A Brief Review of UML & OO Dr. Guoqiang Hu Department of Computer Science UTEP 1.
CS 151: Object-Oriented Design September 26 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Introduction to Unified Modeling Language (UML) By Rick Mercer with help from The Unified Modeling Language User Guide, Grady Booch, James Rumbaugh, Ivar.
An Introduction to the Unified Modeling Language
Discovering object interaction. Use case realisation The USE CASE diagram presents an outside view of the system. The functionality of the use case is.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Interaction Diagrams Interaction Diagrams allow the designer to show how groups of objects collaborate in some behavior. –Interaction Diagrams will show.
CS 151: Object-Oriented Design September 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Object Oriented Analysis and Design Class and Object Diagrams.
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole.
INFSY 535.  Small systems  Larger systems 1.Understand the program requirement- what 3. Write and test each part (unit testing) 4. Maintenance 2. Specify.
CS 151: Object-Oriented Design September 10 Class Meeting
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
CS 160 and CMPE/SE 131 Software Engineering February 25 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
Introduction to UML and Rational Rose UML - Unified Modeling Language Rational Rose 98 - a GUI tool to systematically develop software through the following.
Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 12 – Object-Oriented Design.
Introduction to Unified Modeling Language (UML) By Rick Mercer with help from The Unified Modeling Language User Guide, Grady Booch, James Rumbaugh, Ivar.
CS 160 and CMPE/SE 131 Software Engineering March 8 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
The Object-Oriented Design Process Chapter 2. Chapter Topics From Problem to Code The Object and Class Concepts Identifying Classes Identifying Responsibilities.
Chapter 12 – Object-Oriented Design
UML Diagrams: Class Diagrams The Static Analysis Model
Introduction to Unified Modeling Language (UML)
Advanced Java Programming
CS 174: Server-Side Web Programming February 12 Class Meeting
Introduction to UML Introduction to UML Shiyuan Jin September,23,2002
Introduction to Unified Modeling Language (UML)
CIS 375 Bruce R. Maxim UM-Dearborn
CMPE 135: Object-Oriented Analysis and Design September 6 Class Meeting Department of Computer Engineering San Jose State University Fall 2018 Instructor:
Review CSE116 2/21/2019 B.Ramamurthy.
Chapter 12 – Object-Oriented Design
Software Engineering System Modeling Chapter 5 (Part 1) Dr.Doaa Sami
Classes CS 21a: Introduction to Computing I
CIS 375 Bruce R. Maxim UM-Dearborn
ITEC324 Principle of CS III
CS 151: Object-Oriented Design October 8 Class Meeting
ITEC324 Principle of CS III
CMPE/SE 131 Software Engineering February 22 Class Meeting
Presentation transcript:

CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 2 Class Relationships: Dependency  Class C depends on class D : Some method of C manipulates objects of D Example: Mailbox objects manipulate Message objects.  Dependency is asymmetric. The Message class is not aware of the existence of the Mailbox class. Therefore, Message objects do not depend on Mailbox objects.  Loose coupling Minimize the number of dependency relationships. Another way for a design to handle change. _

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 3 Class Relationships: Aggregation  Class C aggregates class A : Objects of class C contains objects of class A over a period of time.  A special case of dependency. The “has-a” relationship. Example: An Inventory object has a list of Instrument objects.  Multiplicity 1:1 – Example: Each Person object has a single StreetAddress object. 1:n – Example: Each Inventory object has an array of multiple Instrument objects.

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 4 Class Relationships: Inheritance  Class C inherits from class S. The “is-a” relationship. All class C objects are special cases of class S objects. Class S is the superclass of class C. Class C is a subclass of class S. An object of class C is an object of class S.  Note Aggregation: A Mailbox object has a Message object. Inheritance: A ForwardedMessage object is a Message object. _

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 5  Class-Responsibilities-Collaborations  An effective technique to discover classes, responsibilities, and relationships.  CRC card is an index card that Describes one class. Lists its responsibilities. Lists its relationship with other classes. _ The CRC Technique

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 6  Example: class Mailbox The CRC Technique Mailbox ResponsibilitiesRelationships Manage passcodeMessageQueue Manage greeting Create new message

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 7 1. Write the class name on each index card. 2. Distribute the responsibilities among the classes. 3. Find out their relationships and list all dependencies of each classes. 4. Don't write the methods or instance fields. Just write the responsibilities at a high level language. _ The CRC Technique

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 8  A picture is worth a thousand words!  It is much easier to extract information from a graphical notation than reading a textual document.  Show your design in graphical UML diagrams. UML: Unified Modeling Language  There are several different types of UML diagrams. For now, we’ll use Class diagrams Sequence diagrams State diagrams UML Diagrams

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 9  A class diagram has three compartments: UML Class Diagram Class Name Attributes : types Methods(parms : types) : return type

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 10  Specify the most important attributes and methods.  If you have too many attributes in a class, check if you can group them into a new class.  Example: You have attributes that are specific to your class. You have attributes that are specific to your class. But you also have name, street, city, state, and zip attributes. But you also have name, street, city, state, and zip attributes. Create a new Address class to contain those attributes. Create a new Address class to contain those attributes. Then your class has an address. Then your class has an address. UML Class Diagram: Attributes and Methods

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 11 Example UML Class Diagram Mailbox newMessages : ArrayList savedMessages : ArrayList add(msg : Message) : boolean getCurrentMessage() : Message

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 12  Relationships among classes using arrows. UML Class Diagram: Relationships Dependency Aggregation Inheritance Composition Association Direct association Interface implementation

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 13  Multiplicity in a “has” relationship. UML Class Diagram: Multiplicities

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 14 UML Class Diagram: Aggregation  Aggregation A “has a” relationship. A “has a” relationship. The contained object can have an existence independent of its container. The contained object can have an existence independent of its container. Example Example  A mailbox has a set of messages.  A message can exist without a mailbox.  Therefore, a mailbox aggregates messages. Mailbox Message 1*

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 15 UML Class Diagram: Composition Mailbox MessageQueue 11  Composition A “has a” relationship. A “has a” relationship. The contained object cannot (logically) have an existence independent of its container. The contained object cannot (logically) have an existence independent of its container. Example Example  A mailbox has a message queue.  The message queue cannot (logically) exist without a mailbox.  Therefore, a mailbox composes a message queue.

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 16  A class diagram is static. It shows the classes that exist throughout the lifetime of the system.  A sequence diagram shows the dynamic relationships among the classes at run time. It describes interaction among objects over time during run time. _ UML Sequence Diagram

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 17 Customer Withdraw cashKeypadBank Account Display select notify display confirmation enter amount notify verify accept notify display bank ads notify dispense cash TIMETIME Withdraw Cash Sequence Diagram UML Sequence Diagram

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 18  Use underlined font for object names to distinguish between class and object names.  The dashed vertical lines are lifelines.  A rectangle on a lifeline is an activation bar.  It shows when a object has control executing a method.  The activation bar ends when the method returns.  The horizontal arrows are call arrows.  Use a sequence diagram to illustrate complex interactions among a set of objects.  Don't show loops or branches. _ UML Sequence Diagram

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 19  At run time, the state of an object is characterized by the values of its fields.  In some objects, different states can cause different behaviors.  Example: A voice mail system Caller dials voice mail number  the state is "Connected" Caller dials voice mail number  the state is "Connected" If caller dial a valid extension  the state is "Recording" If caller dial a valid extension  the state is "Recording"  If in "Recording" state the caller can type in the passcode  the state is "Main menu“ _ UML State Diagram

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 20 Connected Recording Main menu Main menu Change passcode Change passcode Passcode Entered Hang up # 3 Passcode Entered Extension Entered Hang up UML State Diagram

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 21 Free UML Design Tools  StarUML:  Violet: Dr. Horstmann’s product _ Dr. Horstmann’s product _

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 22  The javadoc utility creates a set of HTML pages for your classes.  It reads specially formatted comments in your code. Delimit comments for javadoc by /** and */ Delimit comments for javadoc by /** and */  It copies the first sentence of your comment to a summary table. Write the first sentence carefully. Write the first sentence carefully. It should start with an uppercase letter and end with a period. It should start with an uppercase letter and end with a period. javadoc

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 23 javadoc  Javadoc comment example: Method paramname explantion Method paramname explantion Function return explanation Function return explanation If the method throws an exceptionname explanation If the method throws an exceptionname explanation /** * Choose the test string with the highest score and return it. sequence the current sequence. store the sequence store. the chosen test string. */ private String chooseString(CurrentSequence sequence, SequenceStore store) {... }

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 24  On the command line: javadoc path /*.java  You can also run javadoc from within NetBeans or Eclipse. _ Run the javadoc Utility Demo

SJSU Dept. of Computer Science Spring 2013: September 3 CS 151: Object-Oriented Design © R. Mak 25  Write only the skeletons of your classes. No implementation initially. No implementation initially. Just include javadoc comments. Just include javadoc comments. The result is an outline summary of your design. The result is an outline summary of your design.  Example: Program Design and javadoc /** * Choose the test string with the highest score and return it. sequence the current sequence. store the sequence store. the chosen test string. */ private String chooseString(CurrentSequence sequence, SequenceStore store) { // To be implemented. }