Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting"— Presentation transcript:

1 CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting
Department of Computer Engineering San Jose State University Spring 2019 Instructor: Ron Mak

2 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).

3 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);

4 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.

5 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;

6 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.

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

8 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

9 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.

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

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

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

13 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

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

15 Video A typical requirements gathering meeting with customers.


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

Similar presentations


Ads by Google