Final review CSE331 Winter 2017.

Slides:



Advertisements
Similar presentations
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Advertisements

FINAL REVIEW. Stronger vs Weaker (one more time!) Requires less? Promises more? (stricter specifications on what the effects entail) Throws more exceptions?
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
Overview of Java (continue). Announcements You should have access to your repositories and HW0 If you have problems getting HW0, let me know If you’ve.
Generic Programming David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 The problem Assume we have a nice Stack implementation. Our stack.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Generic Programming Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 The Problem Assume we have a nice Stack implementation. Our stack receives.
Generic Programming David Rabinowitz. June 14, 2006 Object Oriented Design Course 2 The problem Assume we have a nice Stack implementation. Our stack.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Effective Java: Generics Last Updated: Spring 2009.
Slides by Alex Mariakakis Section 10: Final Review.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Patterns COM379 University of Sunderland James Malone.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Creational Patterns
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
CMSC 330: Organization of Programming Languages Java Generics.
Session 30 Final Review. Final Details Wednesday, December 14 at 8 AM Wright 5 (same classroom) Final will be comprehensive Open book Open notes Test.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 13 Generics 1.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
FINAL REVIEW. Stronger vs Weaker (one more time!) Requires more? Promises more? (stricter specifications on what the effects entail) weaker stronger.
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
1 Design Patterns prepared for COMP314, Bernhard Pfahringer see links on the web page as well!
Generic Programming David Rabinowitz.
Section 9: Design Patterns
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Inheritance and Polymorphism
More on Java Generics Multiple Generic Types Bounded Generic Types
Java Generics Lecture 14 CS2110 – Fall 2016
Generics and Subtyping
Design Patterns (cont.) and Coding
Generic Programming David Rabinowitz.
CSE 331 Subtyping slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Generics, Lambdas, Reflections
object oriented Principles of software design
Section 9: Design Patterns
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
How to be a Good Developer
Java Generics.
Section 9: Design Patterns
Software Engineering Lecture 7 - Design Patterns
Chapter 19 Generics Dr. Clincy - Lecture.
Design Patterns in Game Design
Generics (Parametric Polymorphism)
Material pulled from last section and last year’s slides
Generics.
Generic programming in Java
Material pulled from last section and last year’s slides
Section 8: Design Patterns
Section 9: Design Patterns
Comp 212: Intermediate Programming Lecture 18 – Java Generics
Section 9: Design Patterns
Final review.
Chapter 8, Design Patterns Singleton
Section 9: Design Patterns
Presentation transcript:

Final review CSE331 Winter 2017

Administrivia Final exam practice session: Friday @ CSE 403 from 5:30 – 7:30pm. HW9 designs presentation: Friday in class. If you are interested in presenting, please sign up here: https://piazza.com/class/ixj4iceepbe4m2?cid=723. CSE331 Winter 2017

Stronger vs Weaker (one more time!) •Requires more? •Promises more? (stricter specifications on what the effects entail) CSE331 Winter 2017

Stronger vs Weaker (one more time!) •Requires more? weaker •Promises more? (stricter specifications on what the effects entail) stronger CSE331 Winter 2017

Stronger vs Weaker @return the value associated with key @requires key is a key in this @return the value associated with key @throws NullPointerException if key is null A.@requires key is a key in this and key != null @return the value associated with key B.@return the value associated with key if key is a key in this, or null if key is not associated with any value C. @return the value associated with key @throws NullPointerException if key is null @throws NoSuchElementException if key is not a key this CSE331 Winter 2017

Stronger vs Weaker @return the value associated WEAKER @requires key is a key in this @return the value associated with key @throws NullPointerException if key is null A.@requires key is a key in this and key != null @return the value associated WEAKER B.@return the value associated with key with key if key is a key in this, or null if key is not associated with any value NEITHER C. @return the value associated @throws NullPointerException with key if key is null @throws NoSuchElementException key this STRONGER if key is not a CSE331 Winter 2017

Subtypes & Subclasses of G<Bar> •Subtypes are substitutable for supertypes •If Foo is a subtype of Bar, G<Foo> is a NOT a subtype of G<Bar> •Aliasing resulting from this would let you add objects of type Bar to G<Foo>, which would be bad! •Example: List<String> List<Object> ls = new ArrayList<String>(); lo = ls; lo.add(new Object()); String s = ls.get(0); •Subclassing is done to reuse code (extends) •A subclass can override methods in its superclass CSE331 Winter 2017

Typing and Generics •<?> is a wildcard for unknown •Upper bounded wildcard: type is wildcard or subclass •Eg: List<? extends Shape> •Illegal to write into (no calls to add!) because we can’t guarantee type safety. •Lower bounded wildcard: type is wildcard or superclass •Eg: List<? super Integer> •May be safe to write into. CSE331 Winter 2017

PECS Producer Extends Consumer Super CSE331 Winter 2017

Subtypes & Subclasses lecse; les.add(scholar); class Student extends Object { ... } CSEStudent extends Student { ... } List<Student> ls; Student> ls = lcse; les = lscse; lcse = lscse; List<? List<? super extends les; Student> lss; List<CSEStudent> lcse; List<? List<? super extends CSEStudent> lecse; les.add(scholar); CSEStudent> lscse; lscse.add(scholar); lss.add(hacker); scholar = lscse.get(0); hacker = lecse.get(0); Student scholar; CSEStudent hacker; CSE331 Winter 2017

Subtypes & Subclasses x x x x class Student extends Object { ... } CSEStudent extends Student { ... List<Student> ls; Student> x List<? List<? super extends les; ls = lcse; Student> lss; les = lscse; lcse = lscse; x List<CSEStudent> lcse; List<? extends CSEStudent> lecse; x super CSEStudent> lscse; les.add(scholar); x lscse.add(scholar); lss.add(hacker); Student scholar; CSEStudent hacker; scholar = lscse.get(0);x hacker = lecse.get(0); CSE331 Winter 2017

Subclasses & Overriding class Foo Shoe extends Object { m(Shoe x, Shoe y){ ... } } class Bar extends Foo {...} CSE331 Winter 2017

Method Declarations in Bar The result is method overriding The result is method overloading The result is a type-error None of the above Object ↓ Foo ↓ Bar Footwear ↓ Shoe ↓ HighHeeledShoe •FootWear m(Shoe x, Shoe y) { ... } •Shoe m(Shoe q, Shoe z) { ... } •HighHeeledShoe m(Shoe x, Shoe y) { ... } •Shoe m(FootWear x, HighHeeledShoe y) { ... } •Shoe m(FootWear x, FootWear y) { ... } •Shoe m(Shoe x, Shoe y) { ... } •Shoe m(HighHeeledShoe x, HighHeeledShoe y) { ... } •Shoe m(Shoe y) { ... } •Shoe z(Shoe x, Shoe y) { ... } CSE331 Winter 2017

Method Declarations in Bar The result is method overriding The result is method overloading The result is a type-error None of the above Object ↓ Foo ↓ Bar Footwear ↓ Shoe ↓ HighHeeledShoe •FootWear m(Shoe x, Shoe y) { ... } type-error overriding •Shoe m(Shoe q, Shoe z) { ... } overriding •HighHeeledShoe m(Shoe x, Shoe y) { ... } overloading •Shoe m(FootWear x, HighHeeledShoe y) { ... } •Shoe m(FootWear x, FootWear y) { ... } overloading overriding •Shoe m(Shoe x, Shoe y) { ... } •Shoe m(HighHeeledShoe x, HighHeeledShoe y) { ... } overloading overloading •Shoe m(Shoe y) { ... } •Shoe z(Shoe x, Shoe y) { ... } none (new method declaration) CSE331 Winter 2017

Design Patterns •Creational patterns: get around Java constructor inflexibility •Sharing: singleton, interning •Telescoping constructor fix: builder •Returning a subtype: factories •Structural patterns: translate between interfaces •Adapter: same functionality, different interface •Decorator: different functionality, same interface •Proxy: same functionality, same interface, restrict access •All of these are types of wrappers CSE331 Winter 2017

Design Patterns •Interpreter pattern: •Collects code for similar objects, spreads apart code for operations (classes for objects with operations as methods in each class) •Easy to add objects, hard to add methods •Instance of Composite pattern •Procedural patterns: •Collects code for similar operations, spreads apart code for objects (classes for operations, method for each operand type) •Easy to add methods, hard to add objects •Ex: Visitor pattern CSE331 Winter 2017

Design Patterns •What pattern would you use to… Adapter, Builder, Composite, Decorator, Factory, Flyweight, Iterator, Intern, Interpreter, Model-View-Controller (MVC), Observer, Procedural, Prototype, Proxy, Singleton, Visitor, Wrapper •What pattern would you use to… •add a scroll bar to an existing window object in Swing •We have an existing object that controls a communications channel. We would like to provide the same interface to clients but transmit and receive encrypted data over the existing channel. •When the user clicks the “find path” button in the Campus Maps application (hw9), the path appears on the screen. CSE331 Winter 2017

Design Patterns •What pattern would you use to… Adapter, Builder, Composite, Decorator, Factory, Flyweight, Iterator, Intern, Interpreter, Model-View-Controller (MVC), Observer, Procedural, Prototype, Proxy, Singleton, Visitor, Wrapper •What pattern would you use to… •add a scroll bar to an existing window object in Swing •Decorator •We have an existing object that controls a communications channel. We would like to provide the same interface to clients but transmit and receive encrypted data over the existing channel. •Proxy •When the user clicks the “find path” button in the Campus Maps application (hw9), the path appears on the screen. •MVC •Observer CSE331 Winter 2017