CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting

Slides:



Advertisements
Similar presentations
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Advertisements

Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Inheritance Inheritance Reserved word protected Reserved word super
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Software Testing and Quality Assurance
CISC6795: Spring Object-Oriented Programming: Polymorphism.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1. 2 Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage.
CS 46B: Introduction to Data Structures June 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Effective C#, Chapter 1: C# Language Elements Last Updated: Fall 2011.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
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
Object-Oriented Analysis and Design. Lesson 1: Introduction to Software Engineering.
OO as a language for acm l OO phrase l Mental model of key concepts.
CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
Object-Oriented Data Modeling
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
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
Object Oriented Programming
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
CS 151: Object-Oriented Design October 29 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Inheritance Chapter 11 in Gaddis. Is a relationships in ‘real’ life Exist when one object is a specialized version of another one –Examples An english.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
CMPE 135: Object-Oriented Analysis and Design August 31 Class Meeting
CMPE 280 Web UI Design and Development August 29 Class Meeting
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
CMPE 135: Object-Oriented Analysis and Design September 26 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CS 215 Final Review Ismail abumuhfouz Fall 2014.
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 September 14 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
Inheritance and Polymorphism
Module 5: Common Type System
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Object-Oriented Programming
CMPE 135: Object-Oriented Analysis and Design October 17 Class Meeting
Lecture 2 of Computer Science II
CMPE Data Structures and Algorithms in C++ February 22 Class Meeting
C++ Classes C++ Interlude 1.
Advanced Java Programming
Object Oriented Analysis and Design
CMPE 180A Data Structures and Algorithms in C++ March 8 Class Meeting
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Encapsulation Inheritance PolyMorhpism
CMPE 152: Compiler Design August 23 Class Meeting
Software Design Lecture : 12.
CMPE 135: Object-Oriented Analysis and Design December 6 Class Meeting
ITEC 3220A Using and Designing Database Systems
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Object-Oriented Programming
CMPE 152: Compiler Design January 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design February 5 Class Meeting
CMPE 135: Object-Oriented Analysis and Design March 19 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
CMPE 152: Compiler Design February 28 / March 5 Lab
CMPE 135: Object-Oriented Analysis and Design February 21 Class Meeting Department of Computer Engineering San Jose State University Spring 2019 Instructor:
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 14 Class Meeting
CMPE 152: Compiler Design April 18 – 30 Labs
CMPE 152: Compiler Design March 7/12 Lab
CS 151: Object-Oriented Design October 8 Class Meeting
CMPE 152: Compiler Design August 27 Class Meeting
Presentation transcript:

CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting Department of Computer Engineering San Jose State University Spring 2019 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Overloading vs. Overriding Overloading is the ability to define multiple functions with the same name but with different formal parameters. Parameters differ by number, datatype, or order. Functions cannot differ only in return datatype. Which function is called depends on the arguments. Overriding is the ability of a member function of a subclass to redefine a member function in the superclass with the same signature (name, parameters, and return datatype).

Why Overload Functions perform conceptually similar actions, differing only in their parameters. Examples: Functions perform the same action, only through different parameters. Functions perform equivalent actions with different parameters. void WriteInt(int value); // to standard out void WriteInt(int value, File out); void DrawDot(int x, int y); void DrawDot(Point pt); void WriteMessage(char *text); void WriteMessage(string text);

Why Override The subclass’s member function has the same signature as the superclass’s member function, but the subclass’s function must execute instead of the superclass’s function.

Why Override, cont’d Override.cpp class Employee { public:     double pay() { return rate*hours; }      private:     double rate;     double hours; }; class Manager : public Employee     double pay() {Employee::get_salary() + bonus; }     double bonus;

Midterm Review We looked at code that was functional but was inflexible and hard to maintain. Code that was not able to handle change. We incrementally improved the code. Encapsulated what varied Delegated tasks Wrote code that could scale In the process, we applied good object-oriented design principles.

Midterm Review, cont’d Understand what your customer wants. Functional and nonfunctional requirements UML diagrams: Use case, sequence, class Functional Specification

Midterm Review, cont’d Analysis Dealing with complexity. Where do classes come from? Textual analysis CRC cards (Class Responsibility Collaboration) Class relationships: dependency, inheritance, aggregation, composition Design Specification Design and implementation of the Day class

Midterm Review, cont’d Object-oriented design basics Abstraction Encapsulation Inheritance Polymorphism Object-oriented design principles Encapsulate what varies. Favor composition over inheritance. Code to interfaces, not implementations.

Midterm Review, cont’d Factory classes Accessors and mutators Dangerous setters Immutable classes References to immutable objects

Midterm Review, cont’d Interfaces Law of Demeter (“Principle of Least Knowledge”) Liskov Substitution Principle Cohesion Completeness Convenience Clarity Consistency

Midterm Review, cont’d Programming by contract Precondition Postcondition Invariant Favor composition over inheritance Delegation “Has a” vs. “is a” SimUDuck example

Midterm Review, cont’d Polymorphism Rock-Paper-Scissors game Abstract classes Pure virtual member functions Virtual destructors Rock-Paper-Scissors game Random choice Simple machine learning

Midterm Format Canvas and the lockdown browser. Multiple choice and short answer. Write C++ code snippets.

Video A typical requirements gathering meeting with customers.