Material pulled from last section and last year’s slides

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Advertisements

The Substitution Principle SWE 332 – Fall Liskov Substitution Principle In any client code, if subtype object is substituted for supertype object,
Comp 212: Intermediate Programming Lecture 18 – Java Generics By: Anupam Chanda.
Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns.
FINAL REVIEW. Stronger vs Weaker (one more time!) Requires less? Promises more? (stricter specifications on what the effects entail) Throws more exceptions?
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
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.
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.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
Creational Patterns
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
CMSC 330: Organization of Programming Languages Java Generics.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
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.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
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.
9 Improving structure with inheritance
Sections Inheritance and Abstract Classes
Generic Programming David Rabinowitz.
CSC 243 – Java Programming, Spring 2014
Section 9: Design Patterns
MPCS – Advanced java Programming
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
Generic Programming David Rabinowitz.
Final review CSE331 Winter 2017.
CSE 331 Subtyping slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Generics, Lambdas, Reflections
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.
Type Abstraction SWE Spring 2009.
Generics.
Java Generics.
Section 9: Design Patterns
Subtype Polymorphism, Subtyping vs
CSC 143 Inheritance.
Chapter 19 Generics Dr. Clincy - Lecture.
Generics (Parametric Polymorphism)
Java Generics Lecture 22 CS2110 – Fall 2018
CSE 331 Software Design and Implementation
CSE 331 Software Design and Implementation
Material pulled from last section and last year’s slides
Generics.
Generic programming in Java
Section 8: Design Patterns
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Design Patterns Part 2: Factory, Builder, & Memento
Section 9: Design Patterns
Comp 212: Intermediate Programming Lecture 18 – Java Generics
Section 9: Design Patterns
Final review.
Generics, Lambdas, Reflections
CSC 220 – Processing Spring, 2017
Lecture 13: Subtyping Rules Killer Bear Climber
Chapter 19 Generics.
Type Abstraction SWE Spring 2013.
Section 9: Design Patterns
Presentation transcript:

Material pulled from last section and last year’s slides

Today’s Agenda Administrivia Review Design Patterns Design Pattern Worksheet Course Review

Administrivia HW9 due tonight at 10PM Friday – Final Exam In regular lecture room

Design Patterns Creational patterns: get around Java constructor inflexibility Sharing: singleton, interning, flyweight 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

Design Patterns What pattern would you use to… Adapter, Builder, Decorator, Factory, Flyweight, Intern, Model-View-Controller (MVC), 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

Worksheet time! Solutions will be posted online

Course Review

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

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

Subtypes & Subclasses 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> ls = new ArrayList<String>(); List<Object> 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

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.

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

Subtypes & Overriding class Foo extends Object { Shoe m(Shoe x, Shoe y){ ... } } class Bar extends Foo {...}

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) { ... }

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 Shoe m(Shoe q, Shoe z) { ... } overriding HighHeeledShoe m(Shoe x, Shoe y) { ... } overriding Shoe m(FootWear x, HighHeeledShoe y) { ... } overloading Shoe m(FootWear x, FootWear y) { ... } overloading Shoe m(Shoe x, Shoe y) { ... } overriding Shoe m(HighHeeledShoe x, HighHeeledShoe y) { ... } overloading Shoe m(Shoe y) { ... } overloading Shoe z(Shoe x, Shoe y) { ... } none (new method declaration)

Exam You got this! We believe in you! Friday (tomorrow) 1:10PM!