Computer Science 313 – Advanced Programming Topics.

Slides:



Advertisements
Similar presentations
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Advertisements

Lab class 10: 1. Analyze and implement the following merge-sorting program. //import java.lang.*; public class MergeSorter { /** * Sort the elements of.
Computer Science 313 – Advanced Programming Topics.
C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
UML Class Diagram: class Rectangle
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
Computer Science 313 – Advanced Programming Topics.
Object Oriented Software Development
CISC6795: Spring Object-Oriented Programming: Polymorphism.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
Object Adapter Pattern Danny Leavitt. Imagine... You program for the control center of a US phone company. Your network managment software is Object Oriented.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Prof. Hertz (as told by xkcd.com)‏. Computer Science 313 – Advanced Programming Topics.
Partitioning and Layering Fundamentals. The Basic Problem Change is a fact of life RequirementsTechnologies Bug Fixes Software Must Adapt.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
Distributed Java Programming Distributed Java Programming Class #2 August 22, 2002.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
CSC 395 – Software Engineering Lecture 14: Object-Oriented Analysis –or– Ripping the Band-Aid Off Quickly.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
1 Advanced Polymorphism Polymorphism Review Comparator Interface Sorting with Comparators Selection Sort Insertion Sort.
By Shishir Kumar Contact:
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
Computer Science 313 – Advanced Programming Topics.
CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
CSC 313 – Advanced Programming Topics. Strategy Pattern Usage public class RubberDuck extends Duck { FlightBehavior flyBehavior; QuackBehavior quackBehavior;
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Inheritance Revisited Other Issues. Multiple Inheritance Also called combination--not permitted in Java, but is used in C++ Also called combination--not.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
ITEC 320 Lecture 9 Nested records / Packages. Review Project ?’s Records Exam 1 next Friday.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Topic 7 Interfaces I once attended a Java user group meeting where James Gosling (one of Java's creators) was the featured speaker. During the memorable.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 350 – Software Design The Adapter Pattern – Chapter 7 Gang of Four Definition: Convert the interface of a class into another interface that the client.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
COP 2220 Computer Science I Topics –Breaking Problems Down –Functions –User-defined Functions –Calling Functions –Variable Scope Lecture 4.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Computer Science 313 – Advanced Programming Topics.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
COP 3330 Notes 4/13. Today’s Topics UML Class Diagrams.
Design Patterns: Brief Examples
By SmartBoard team Adapter pattern.
Section 11.1 Class Variables and Methods
Advanced Programming Behnam Hatami Fall 2017.
by Manish Shah & Eugene Park CSPP 523 Jan.21, 2002
Adapter Pattern 1.
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Introduction to Design Patterns
Adapter Design Pattern
Presentation transcript:

Computer Science 313 – Advanced Programming Topics

Real-World Problems  Have one thing, but need something different  Try & make it work despite not being correct  But this often leads to problems

Outlets Around the World  2 standards for electric transmission  Japan & the Americas use 110 volt  220 volts used by Europe, (rest of) Asia, & Africa  Variety of incompatible plugs defined by each

Play With Electricity for Fun!  Do not want new appliance for each country  First thought: jam single plug into wall  Plug interface only difference between them

Play With Electricity for Fun!  Do not want new appliance for each country  First thought: jam single plug into wall  Plug interface only difference between them

Play With Electricity for Fun!  Do not want new appliance for each country  First thought: jam single plug into wall  Plug interface only difference between them  Generally speaking, this is not a good idea  Use plug adapter as an alternate approach  Plug then good to use in existing outlets now

Adapter Pattern Workings  Like plug adapters, but used with existing code  Starts with some existing plug (instance)  Need it to match a preexisting outlet (interface)  Do not want big changes; functionality stays same  Change what is exposed by wrapping plug

Adapter Pattern Intent  Makes existing class use client's interface  Otherwise compatible classes now work together  Work is invisible to client code  Goal of pattern is client code is not modified  No changes to functionality with this pattern  If we want real changes use D ECORATOR PATTERN  Does not need to expose full functionality  Have not discussed what plug attached to!

Adapter Pattern Example  Already wrote class sorting an array public interface Comparable { public int compareTo(T other); } public class QuickSort { static void > sort(T[] array) { // Sorts this array } }

Points on a Plane  Must sort, but Dimension s not Comparable  Rewrite QuickSort to use Dimension s  Dimension closed to modification & inheritance  Do not want to rerun tests on Dimension, anyway  Adapter does this without violating laziness principle  Two ways to do this with A DAPTER PATTERN  Hide object, via Object adapter using composition  Class adapter uses inheritance, but reuse limited

Object Adapter class ComparableDimension implements Comparable { private Dimension d; // Object being adapted public ComparableDimension(Dimension newD) { d = newD; } public int compareTo(ComparableDimension o) { Integer myArea = d.height * d.width; Integer oArea = o.d.height * o.d.width; return myArea.compareTo(oArea); } }

Class Adapter class ComparableDimension extends Dimension implements Comparable { public ComparableDimension(int h, int w) { super(h, w); } public int compareTo(ComparableDimension o) { Integer myArea = d.height * d.width; Integer oArea = o.d.height * o.d.width; return myArea.compareTo(oArea); } }

How Example Works  Implementing ComparableDimension either way  Is-a or Has-a Dimension to compare  Comparable interface is implemented  Can be used by QuickSort class

Class Adapter UML Diagram is-a  Adapter extends Target & is-a Adaptee  Not very easy in Java  Client, Target & Adaptee already exist  Only Adapter created or edited to do this

Class Adapter UML Diagram is-a  Adapter extends Target & is-a Adaptee  Not very easy in Java  Client, Target & Adaptee already exist  Only Adapter created or edited to do this

Object Adapter UML Diagram has-a  Adapter extends Target & has-a Adaptee  No multiple inheritance, so legal in Java  Client, Target & Adaptee already exist  Only Adapter created or edited to do this

Object Adapter UML Diagram has-a  Adapter extends Target & has-a Adaptee  No multiple inheritance, so legal in Java  Client, Target & Adaptee already exist  Only Adapter created or edited to do this

For Next Class  Lab #6 available on Angel  Assignment due before we go on break  Will discuss Façade pattern on Wednesday  How does this differ from Adapter?  What is important when discussing patterns?  What is the most “Hollywood” of patterns?