CMPE 135: Object-Oriented Analysis and Design March 19 Class Meeting

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
CS 151: Object-Oriented Design September 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 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 151: Object-Oriented Design September 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Programming in Java CSCI-2220 Object Oriented Programming.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
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
CMPE 226 Database Systems October 28 Class Meeting
CS 152: Programming Language Paradigms March 19 Class Meeting Department of Computer Science San Jose State University Spring 2014 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
CMPE 226 Database Systems April 19 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Advanced Programming in Java
CMPE 135: Object-Oriented Analysis and Design September 26 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CMPE Data Structures and Algorithms in C++ September 14 Class Meeting
CMPE 135: Object-Oriented Analysis and Design October 3 Class Meeting
Advanced Object-Oriented Programming Features
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
Polymorphism.
CMPE 135: Object-Oriented Analysis and Design October 17 Class Meeting
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
CS 153: Concepts of Compiler Design November 30 Class Meeting
Programming Language Concepts (CIS 635)
CMPE419 Mobile Application Development
CMPE 180A Data Structures and Algorithms in C++ February 15 Class Meeting Department of Computer Engineering San Jose State University Spring 2018 Instructor:
CMPE 152: Compiler Design ANTLR 4 and C++
CMPE 152: Compiler Design February 6 Class Meeting
Object Oriented Programming
CMPE 180A Data Structures and Algorithms in C++ March 8 Class Meeting
CSC 113 Tutorial QUIZ I.
CMPE 152: Compiler Design August 23 Class Meeting
Polymorphism Polymorphism
CMPE 135: Object-Oriented Analysis and Design November 27 Class Meeting Department of Computer Engineering San Jose State University Fall 2018 Instructor:
CMPE 152: Compiler Design August 28/30 Lab
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
CMPE 152: Compiler Design January 29 Class Meeting
CS 144 Advanced C++ Programming February 12 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:
CS 144 Advanced C++ Programming January 24 Class Meeting
Final and Abstract Classes
CS 144 Advanced C++ Programming February 21 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
CMPE 135: Object-Oriented Analysis and Design March 14 Class Meeting
CMPE 152: Compiler Design April 18 – 30 Labs
CMPE 152: Compiler Design March 5 Class Meeting
CS 144 Advanced C++ Programming April 9 Class Meeting
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
CS 144 Advanced C++ Programming April 11 Class Meeting
CMPE 152: Compiler Design March 19 Class Meeting
CMPE 152: Compiler Design March 7/12 Lab
CS 151: Object-Oriented Design October 8 Class Meeting
Lecture 6: Polymorphism
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
CMPE 152: Compiler Design August 27 Class Meeting
Presentation transcript:

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

Midterm Solution: Question #41 Briefly describe how delegation can help to encapsulate changes. A class delegates functionality or behavior to another class that it aggregates. Delegation is often used for functionality/behavior that can vary. Therefore, the delegate class is encapsulating what can change.

Midterm Solution: Question #42 How would you write the declaration of a pure virtual member function named foo that takes no parameters and returns void? virtual void foo() = 0;

Midterm Solution: Question #43 Briefly describe how the principle of Coding to the Interface and polymorphism work together. You have a superclass (the interface) that has several subclasses. Each subclass overrides one or more member functions of the superclass. You have a target variable that has the superclass type. At run time, you code to the interface by assigning to that target variable an object instantiated from one of the subclasses. Then when you call an overridden member function on the target variable, polymorphism determines which subclass’s member function is called depending on the subclass type of the instantiated object.

Midterm Solution: Question #44 Briefly describe how the principle of Coding to the Interface and a factory class work together. You have a superclass (the interface) that has several subclasses. You code to the interface by having a target variable that has the superclass type. At run time, you need the flexibility to assign to the target variable an object instantiated from any one of the subclasses. You can use a factory class with a create function that creates and returns a pointer to such an object. An argument to the create function determines which subclass it instantiates, and the argument’s value is set at run time.

Midterm Solution, cont’d Date Calendar Gregorian Lunar Calendar *cal = CalendarFactory::create(type); cal->set(Calendar::YEAR, 2019); cal->set(Calendar::MONTH, Calendar:: FEBRUARY); cal->set(Calendar::DATE, 14);

wx-RPS: MacOS X

wx-RPS: Linux

wx-RPS: Windows 10 Why does the app look so ugly on Windows?

Tutorials My tutorials: http://www.cs.sjsu.edu/~mak/tutorials/index.html Install VirtualBox Install Ubuntu Install wxWidgets on Ubuntu

Install wxWidgets on Mac OS X On the command line: This will install wxWidgets in /usr/local/Cellar/wxmac/3.0.4_1 See: http://web.eng.fiu.edu/watsonh/eel3160/WxMac.pdf brew install wxmac

Create wxWidgets Apps in Eclipse Create a C++ project in Eclipse and open the Properties dialog box. In the left panel, select C/C++ Build | Settings

Create wxWidgets Apps in Eclipse, cont’d GCC C++ Compiler Dialect: Includes: Include paths Preprocessor: Defined symbols (-D) Miscellaneous: Other flags C++11 /usr/local/Cellar/wxmac/3.0.4_1/lib/wx/include/osx_cocoa-unicode-static-3.0 /usr/local/Cellar/wxmac/3.0.4_1/include/wx-3.0 __WXOSX_COCOA__ WXUSINGDLL _FILE_OFFSET_BITS=64 -c -mmacosx-version-min=10.14 -fmessage-length=0 -fvisibility=hidden -fvisibility-inlines-hidden

Create wxWidgets Apps in Eclipse, cont’d MacOS X C++ Linker Libraries (-l) Library search path (-L) Miscellaneous: Linker flags (one long line) wx_osx_cocoau_adv-3.0 wx_osx_cocoau_core-3.0 wx_baseu-3.0 png z jpeg lzma pthread iconv /usr/local/Cellar/wxmac/3.0.4_1/lib -mmacosx-version-min=10.14 -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -framework OpenGL -framework Security

Button Demo

Button Demo, cont’d ButtonPanel.h class ButtonPanel : public wxPanel {     ButtonPanel(wxFrame *parent) : wxPanel(parent, wxID_ANY)     {         init();     } // Event handlers     void on_rock(wxCommandEvent& event);     void on_paper(wxCommandEvent& event);     void on_scissors(wxCommandEvent& event); private:     wxStaticText *button_chosen_text;     void init();     void update_button_choice_text(const Choice choice); };

Button Demo, cont’d ButtonPanel.cpp #include "ButtonPanel.h" void ButtonPanel::init() {     wxSizer *sizer = new wxBoxSizer(wxVERTICAL);     wxPanel *button_panel = new wxPanel(this, wxID_ANY);     wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);     wxStaticText *choose_text = new wxStaticText(button_panel, wxID_ANY,                                                  "Choose:");     wxButton *rock_button     = new wxButton(button_panel, wxID_ANY,                                              choice_to_wxString(ROCK));     wxButton *paper_button    = new wxButton(button_panel, wxID_ANY,                                              choice_to_wxString(PAPER));     wxButton *scissors_button = new wxButton(button_panel, wxID_ANY,                                              choice_to_wxString(SCISSORS)); ...

Button Demo, cont’d ...     rock_button->Bind    (wxEVT_BUTTON, &ButtonPanel::on_rock, this);     paper_button->Bind   (wxEVT_BUTTON, &ButtonPanel::on_paper, this);     scissors_button->Bind(wxEVT_BUTTON, &ButtonPanel::on_scissors, this);     button_sizer->Add(choose_text, 0, 0, 0);     button_sizer->AddSpacer(5);     button_sizer->Add(rock_button, 0, 0, 0);     button_sizer->Add(paper_button, 0, 0, 0);     button_sizer->Add(scissors_button, 0, 0, 0);     button_panel->SetSizer(button_sizer);     wxPanel *chosen_panel = new wxPanel(this, wxID_ANY);     wxSizer *chosen_sizer = new wxGridSizer(2, 0, 5);

Button Demo, cont’d ...     wxStaticText *chosen_text = new wxStaticText(chosen_panel, wxID_ANY,                                                  "Chosen object:");     button_chosen_text = new wxStaticText(chosen_panel, wxID_ANY, "");     button_chosen_text->SetFont(button_chosen_text->GetFont().Larger());     chosen_sizer->Add(chosen_text, 0, wxALIGN_RIGHT, 0);     chosen_sizer->Add(button_chosen_text, 0, 0, 0);     chosen_panel->SetSizer(chosen_sizer);     sizer->Add(button_panel, 0, wxALIGN_CENTER, 0);     sizer->AddSpacer(20);     sizer->Add(chosen_panel, 0, wxALIGN_CENTER, 0);     SetSizer(sizer); }

Button Demo, cont’d void ButtonPanel::on_rock(wxCommandEvent& event) {     update_button_choice_text(ROCK); } void ButtonPanel::on_paper(wxCommandEvent& event)     update_button_choice_text(PAPER); void ButtonPanel::on_scissors(wxCommandEvent& event)     update_button_choice_text(SCISSORS); void ButtonPanel::update_button_choice_text(const Choice choice)     button_chosen_text->SetLabelText(choice_to_wxString(choice));

Assignment #5. GUI-Based RPS Game Develop an GUI-based version of your Rock-Paper-Scissors game. Sample:

Assignment #5, cont’d Minimum features Which round A way for the user to enter a choice for each round. The computer’s prediction of the human’s choice for the round. The computer’s choice for the round. Who the winner is (or is it a tie) of the round. The number of human and computer wins, and the number of ties.

Assignment #5, cont’d Menu commands The default is 20 rounds per game. About Exit Start a new game The default is 20 rounds per game. Provide a way for the human player to change that number. Due Monday, April 8 (after Spring Break)