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

Slides:



Advertisements
Similar presentations
CS 174: Web Programming April 28 Class Meeting
Advertisements

Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Java boot camp1 Subclasses Concepts: The subclass and inheritance: subclass B of class A inherits fields and methods from A. A is a superclass of B. Keyword.
Graphics Programming with Inheritance Template pattern (Chap 6, se SceneEditor)
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Introduction to Computer Science I.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 185C: The History of Computing August 24 Class Meeting Department of Computer Science San Jose State University Fall 2011 Instructor: Ron Mak
CS 61B Data Structures and Programming Methodology July David Sun.
CPSC 2100 University of Tennessee at Chattanooga – Spring 2013 Object-Oriented Design & Patterns 2 nd edition Cay S. Horstmann Chapter 6: Inheritance and.
CS 151: Object-Oriented Design December 5 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 235: User Interface Design April 7 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II March 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 152: Programming Language Paradigms April 9 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS 235: User Interface Design November 3 Class Meeting Department of Computer Science San Jose State University Fall 2014 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
CS 157B: Database Management Systems II March 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
 2002 Prentice Hall. All rights reserved. 1 Introduction to Inheritance Inheritance: –1 of 3 main features of OOP –Form of software reusability –(Derived)
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 149: Operating Systems April 7 Class Meeting Department of Computer Science San Jose State University Spring 2015 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 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 September 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
MIT AITI 2004 – Lecture 12 Inheritance. What is Inheritance?  In the real world: We inherit traits from our mother and father. We also inherit traits.
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
CSSE501 Object-Oriented Development. Chapter 13: Multiple Inheritance  In this chapter we will investigate some of the problems that can arise when a.
Inheritance and Design CSIS 3701: Advanced Object Oriented Programming.
CS 151: Object-Oriented Design October 31 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CMPE 226 Database Systems November 18 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design November 16 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 153: Concepts of Compiler Design November 18 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS100A, 15 Sept Lecture 5 1 CS100A, 5 Sept This lecture continues the discussion of classes. The important new concept of this lecture is.
CS100A, Fall Lecture 5 1 CS100A, Fall 1997 Lecture, Tuesday, 16 September. This lecture continues the discussion of classes. The important new concept.
CS 235: User Interface Design April 28 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 174: Web Programming November 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 151: Object-Oriented Design November 19 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 154 Formal Languages and Computability April 19 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 160 and CMPE/SE 131 Software Engineering May 12 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 154 Formal Languages and Computability May 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 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
CS 160 and CMPE/SE 131 Software Engineering April 19 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CMPE 135: Object-Oriented Analysis and Design October 3 Class Meeting
CS 153: Concepts of Compiler Design August 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design November 21 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CMPE Database Systems Exercise #1 Solutions
ITEC324 Principle of CS III
CMPE 152: Compiler Design August 23 Class Meeting
CMPE 135: Object-Oriented Analysis and Design December 6 Class Meeting
CMPE 135: Object-Oriented Analysis and Design November 29 Class Meeting Department of Computer Engineering San Jose State University Fall 2018 Instructor:
CMPE 152: Compiler Design December 6 Class Meeting
CMPE Database Systems Exercise #3 Solutions
CMPE 152: Compiler Design November 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design November 29 Class Meeting Department of Computer Engineering San Jose State University Fall 2018 Instructor:
CMPE/SE 131 Software Engineering May 9 Class Meeting
CS 144 Advanced C++ Programming March 14 Class Meeting
CMPE 135: Object-Oriented Analysis and Design February 28 Class Meeting Department of Computer Engineering San Jose State University Spring 2019 Instructor:
CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting
CS 144 Advanced C++ Programming March 28 Class Meeting
ITEC324 Principle of CS III
CS 144 Advanced C++ Programming April 25 Class Meeting
CS 151: Object-Oriented Design October 8 Class Meeting
Chapter 6 Inheritance.
CMPE 152: Compiler Design May 2 Class Meeting
CS/SE 157B Database Management Systems II April 24 Class Meeting
Presentation transcript:

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

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 2

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 3 Midterm Results Median75.0 Mean76.7 Standard deviation12.1

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 4 Unofficial Field Trip  Computer History Museum in Mt. View  Saturday, December 7, 11:30 – closing time Special free admission. Do a self-guided tour of the new Revolution exhibit. See a life-size working model of Charles Babbage’s Difference Engine in operation, a hand-cranked mechanical computer designed in the early 1800s. Experience a fully restored IBM 1401 mainframe computer from the early 1960s in operation.  General info:  My summer seminar:  Restoration: thelen.org/1401Project/1401RestorationPage.htmlhttp://ed- thelen.org/1401Project/1401RestorationPage.html

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 5 Unofficial Field Trip  The new Revolution exhibit is now open! Walk through a timeline of the First 2000 Years of Computing History. Historic computer systems, data processing equipment, and other artifacts. Small theater presentations. Atanasoff-Berry Computer Hollerith Census Machine

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 6 Unofficial Field Trip  Babbage Difference Engine, fully operational Hand-cranked mechanical computer. Computed polynomial functions. Designed by Charles Babbage in the early to mid 1800s.  Arguably the world’s first computer scientist, lived He wasn’t able to build it because he lost his funding.  Live demo at 1:30  His plans survived and this working model was built. Includes a working printer!

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 7 Unofficial Field Trip  IBM 1401 computer, fully restored and operational A small transistor-based mainframe computer. Extremely popular with small businesses in the late 1950s through the mid 1960s  Maximum of 16K bytes of memory.  800 card/minute card reader (wire brushes).  600 line/minute line printer (impact).  6 magnetic tape drives, no disk drives.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 8 Extra Credit!  There will be extra credit if you participate in the visit to the Computer History Museum. Complete a Canvas quiz whose answers are to be found among the museum exhibits and presentations. Up to n points added to your midterm score.  n = the number of quiz questions _

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 9 Team Exercise: UML Class Diagram  A company has a manufacturing division and a research division.  The company has a president and two vice presidents. One VP runs manufacturing and the other runs research.  Each division has employees other than its VP, and it might also have an administrative assistant.  All manufacturing workers are union members, but none of the researchers. All of the researchers have college degrees, as do some of the manufacturing employees.  Each employee is paid either by the hour, biweekly, or monthly. Manufacturing workers can get overtime pay, but not researchers. All employees except the president and vice presidents can get bonuses.  The company manufactures different products, three of which are widgets, gadgets, and gizmos. A gadget can be sold separately, or several can be bundled with a widget. A gizmo can only be sold as part of a gadget.  The researchers are working on projects to improve the company’s existing products or to design new products.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 10 An Exercise Solution Vice President Administrative Assistant 0..1 Research Manufacturing Division Company College Degree President «interface» Overtime Pay «interface» Union Member Product * 0..1 Gizmo Gadget Widget «interface» Bonus Employee > Pay Hourly Biweekly Monthly * * Worker * Researcher * Project New product

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 11 Inheritance  By now, inheritance should be a familiar concept. From: Object-Oriented Design & Patterns, John Wiley & Sons, 2006.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 12 Manager extends Employee public class Employee { public Employee(String aName) { name = aName; } public void setSalary(double aSalary) { salary = aSalary; } public String getName() { return name; } public double getSalary() { return salary; } private String name; private double salary; } public class Manager extends Employee { public Manager(String aName) {... } public void setBonus(double aBonus) { bonus = aBonus; } // new method public double getSalary() {... } // overrides Employee method private double bonus; // new field } What are the differences between Manager and Employee ?

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 13 Superclasses and Subclasses  Employee is the superclass Manager is the subclass A manager “is a” employee. A manager is a specialized type of employee. The set of Manager objects is a subset of the set of Employee objects. _ From: Object-Oriented Design & Patterns, John Wiley & Sons, 2006.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 14 Class Hierarchies  AKA inheritance hierarchies  In the real world, hierarchies express general/specific relationships among concepts. The most general concept is at the root of a tree. More specific concepts are children. The most specific concepts are leafs.  Object-oriented programming uses class hierarchies. The most general superclass is at the root of a tree. More specific subclasses are children. The most specific subclasses are leafs.  Class hierarchies can be complex. But they shouldn’t be.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 15 Class Hierarchies From: Object-Oriented Design & Patterns, John Wiley & Sons, 2006.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 16 Class Hierarchies From: Object-Oriented Design & Patterns, John Wiley & Sons, 2006.

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 17 The Liskov Substitution Principle  Named after Barbara Liskov MIT computer science professor Pioneer in object-oriented programming  In your Java code, you should be able to substitute a superclass object by a subclass object: Employee e = new Employee("John Doe"); System.out.println("salary = " + e.getSalary()); Superclass Employee e = new Manager("Mary Jane"); System.out.println("salary = " + e.getSalary()); Subclass

SJSU Dept. of Computer Science Fall 2013: October 29 CS 151: Object-Oriented Design © R. Mak 18 The Liskov Substitution Principle  The type of variable e is Employee The type of the object is Manager. How does Java know which getSalary() method to invoke at run time? The JVM uses the type of the object, not the type of the variable. Polymorphism  How is the Liskov Substitution Principle related to the principle of Programming to the Interface? The type of variable e is the superclass Employee instead of the more specific subclass type Manager. Employee e = new Manager("Mary Jane"); System.out.println("salary = " + e.getSalary());