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

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

Computer Science 2 Data Structures V section 2 Recitation 1.
Advanced Object Oriented Programming Chapter 3 & 4.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Object Oriented Software Development
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
CS 46B: Introduction to Data Structures July 7 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
CS 160: Software Engineering October 8 Class Meeting
CS 152: Programming Language Paradigms February 24 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
CS 235: User Interface Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 151: Object-Oriented Design October 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Java Classes Using Java Classes Introduction to UML.
CS 2430 Day 9. Announcements Quiz on Friday, 9/28 Prog1: see , see me as soon as possible with questions/concerns Prog2: do not add any public methods.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 174: Web Programming September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
CS 46B: Introduction to Data Structures June 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
CS 151: Object-Oriented Design September 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CSE 219 Computer Science III Program Design Principles.
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 160: Software Engineering October 6 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 151: Object-Oriented Design October 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design September 26 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design September 3 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
UML Class Diagrams 1 These lecture slides are copyright (C) Marty Stepp, They may not be rehosted, sold, or modified without expressed permission.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design August 27 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
CS 153: Concepts of Compiler Design October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
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
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
CS 151: Object-Oriented Design August 29 Class Meeting Department of Computer Science San Jose State University Spring 2012 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 151: Object-Oriented Design October 1 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design September 10 Class Meeting
Lect Chap 3 (cont.) 2/2. Chapter 3 The Importance of Encapsulation Even a simple class can benefit from different implementations Users are.
CS 151: Object-Oriented Design October 29 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 46B: Introduction to Data Structures June 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
CS 235: User Interface Design March 17 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 151: Object-Oriented Design September 17 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 367 Introduction to Data Structures Charles N. Fischer Fall s367.html.
CS 46B: Introduction to Data Structures July 23 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
CS 153: Concepts of Compiler Design September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 151: Object-Oriented Design November 26 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Unified Modeling Language (UML)
CS 152: Programming Language Paradigms April 28 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
CS 151: Object-Oriented Design December 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CMPE 135: Object-Oriented Analysis and Design August 31 Class Meeting
CMPE 280 Web UI Design and Development August 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design September 26 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CS 153: Concepts of Compiler Design August 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design September 14 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CMPE 135: Object-Oriented Analysis and Design September 12 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
CMPE Data Structures and Algorithms in C++ February 22 Class Meeting
CMPE 152: Compiler Design September 11/13 Lab
CMPE 152: Compiler Design August 23 Class Meeting
CMPE 152: Compiler Design January 29 Class Meeting
CS 144 Advanced C++ Programming February 21 Class Meeting
CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting
CS 144 Advanced C++ Programming April 9 Class Meeting
CS 151: Object-Oriented Design October 8 Class Meeting
On to Object Design c. 14.
Presentation transcript:

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

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 2 Design a Day Class  Answer questions such as How many days between now and the end of the year? What day is 100 days from now?  A Day object represents a particular day.  Some limitations Uses the Gregorian calendar only No time of day No timezone _

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 3 Methods of the Day Class Day(int year, int month, int date) Constructor. int daysFrom(Day d) Return the number of days between day d and the day represented by the object. The return value can be negative if day d comes before, or 0 if it’s the same day. Example: int n = today.daysFrom(birthday); Day addDays(int count) Return the day that is count days from the day represented by the object. The count value can be negative. Example: Day later = holiday.addDays(5); int getYear() int getMonth() int getDate() Getter methods.

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 4 The Day Class  Note that d.addDays(n).daysFrom(d) equals n  (d + n) - d == n d1.addDays(d2.daysFrom(d1)) equals d2  d1 + (d2 - d1) == d2  Methods daysFrom() and addDays() are not trivial! April, June, September, November have 30 days. February has 28 days, except in leap years it has 29 days All other months have 31 days. Leap years are divisible by 4, except after 1582, years divisible by 100 but not 400 are not leap years. There is no year 0; year 1 is preceded by year -1. In the switchover to the Gregorian calendar, ten days were dropped: October 15, 1582 is preceded by October 4.

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 5 Class Day Implementation, Version 1  Private fields private int year private int month private int date  Private helper methods private Day nextDay() private Day previousDay() private int compareTo(Day other) private static int daysPerMonth(int y, int m) private static boolean isLeapYear(int y)  Inefficient day-at-a-time calculations. Methods nextDay() and previousDay() do all the dirty work. Extraneous Day objects created and discarded.

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 6 Class Day Implementation, Version 2  Instead of private year, month, and date fields, use a Julian day number, the number of days from January 1, 4713 BCE. private int julian  Now public methods daysFrom() and addDays() are trivial.  Private helper methods do all the dirty work of converting back and forth between Julian numbers and [year, month, date]. private static int toJulian(int year, int month, int date) private static int[] fromJulian(int j) Conversion required for each access of year, month, or date.

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 7 Class Day Implementation, Version 3  Keep year, month, date, and julian number fields.  Do conversions between [year, month, date] and julian number only when necessary (lazy conversion). Convert to julian number only when doing date arithmetic. Convert to [year, month, date] only if calling a get * () method.  Need two private booleans fields and two private methods to keep [year, month, date] and julian number fields synchronized: private boolean ymdValid private boolean julianValid private void ensureJulian() private void ensureYmd()

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 8 Importance of Encapsulation  Three different implementations of the Day class.  Each version presents the same public interface. Encapsulation hides the implementation details.  Principles: A class should expose as few public fields and public methods as possible. All other fields and methods should be hidden from class users by making them private.  Supports reliability and flexibility. _

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 9 Assignment #2  Write the first draft of your Design Specification for the Rock-Paper-Scissors game application.  Due Tuesday, September 24 _

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 10 Assignment #2  CRC cards for your classes. You do not need to turn in actual index cards or to draw boxes to represent the cards. For each card, simply give the name of the class and then list the class responsibilities and list the collaborators (dependent classes). _

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 11 Assignment #2  UML class diagrams for your classes.  You can optionally put the class diagrams inside UML package diagrams.  Show the relationships between classes using the appropriate connectors.  At this early design stage, you don’t need to show attributes and methods in the class diagrams, and you don’t need to label associations with attribute names.  However, you should show any multiplicity. _

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 12 Assignment #2  UML sequence diagram  Show the communication patterns among your objects at run time for key operations of your application.  At this early design stage, you should probably not have more than 10 to 12 classes and interfaces.  Use a UML drawing tool to create the diagrams and insert the diagrams into your specification. Violet : StarUML:

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 13 Assignment #2  Design tips The way each player’s choice (rock, paper, or scissors) is input will change.  Early versions of the program will be command-line-based and later versions will be GUI-based. You will soon be exploring different algorithms for how the computer makes its choice.

SJSU Dept. of Computer Science Fall 2013: September 12 CS 151: Object-Oriented Design © R. Mak 14 Assignment #2  Update your Functional Specification Add and modify requirements or use cases, etc. Turn on “Track Changes” under the “Tools” menu so that the changes to the document are obvious.  both documents as attachments to Subject: CS 153 Assignment #2 team name _