Computer Science 313 – Advanced Programming Topics.

Slides:



Advertisements
Similar presentations
TE Sessions Supported by: Basic Concepts of Programming November 3, 2012.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 4 Inheritance and Polymorphism.
Excel Chapter 6 Review slides. How many worksheets are in a workbook, by default? three.
Computer Science 313 – Advanced Programming Topics.
Computer Science 313 – Advanced Programming Topics.
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:
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Template Method By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
CPSC150 Abstract Classes Chapter 10. CPSC150 Directory Example (note: your assignment does not have all of this) DirectoryEntry name phone public void.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Csci5233 Computer Security1 GS: Chapter 5 Asymmetric Encryption in Java.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
CS 240 Week 3. List’Em java Grep [-r] directoryName fileSelectionPattern substringSelectionPattern Run Demo java LineCount [-r] directoryName fileSelectionPattern.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CS 2430 Day 9. Announcements Quiz on Friday, 9/28 Prog1: see , see me as soon as possible with questions/concerns Prog2: do not add any public methods.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
Prof. Hertz (as told by xkcd.com)‏. Computer Science 313 – Advanced Programming Topics.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
1 Biggest issue!!! You can’t do questions on this topic correctly unless you draw variables, draw objects when they are created, and draw frames for method.
Template Design Pattern Kalim Baig. Summary What is Template? What is Template? Definition Definition Problem Problem How might it help the designer How.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
ICS 201 Introduction to Computer Science
Inheritance Dwight Deugo Nesa Matic
1 Computer Science 340 Software Design & Testing Inheritance.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
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.
CPS 100, Fall GridGame APT How would you solve this problem using recursion?
Using EBSCOhost databases Access via MyAthens Click on the EBSCOhost link.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Inheritance (Part 5) Odds and ends 1. Static Methods and Inheritance  there is a significant difference between calling a static method and calling a.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance (Part 2) KomondorBloodHound PureBreedMix Dog Object.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Computer Science 313 – Advanced Programming Topics.
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.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Web Design & Development Lecture 9
Template Method Pattern Iterator Pattern
Data Structures and Algorithms revision
COMPSCI 107 Computer Science Fundamentals
Chapter No. : 1 Introduction to Java.
OBJECT ORIENTED PROGRAMMING II GEORGE KOUTSOGIANNAKIS
Introduction to javadoc
Abstract Classes.
Introduction to Behavioral Patterns (3)
COMPUTER 2430 Object Oriented Programming and Data Structures I
An overview of Java, Data types and variables
Introduction to javadoc
Chapter 9 Carrano Chapter 10 Small Java
Inheritance and Polymorphism
Presentation transcript:

Computer Science 313 – Advanced Programming Topics

Template Method Intent  Enable specialization of general algorithm  Superclass defines algorithm skeleton & basics  Skeleton filled out and detailed by subclasses  Client uses algorithm without needing specifics  Makes coding simple as possible  General algorithm coded in the superclass  Defines simple method(s) uncluttered by detail  Focus on the details left to subclasses  Subclass methods simplified by monofocus

In the Beginning…

Template Method Example  Consider creating a log of program actions:  Store in an HTML file for display on web  Create easy searching by writing simple text file  results for immediate action

Logger Algorithm Input: String of text to log 1. Create new file in which results stored 2. If file needs a header to be correct 1. Print out the file header 3. Print out the text to the file 4. If file trailer is needed for correctness 1. Print out the file trailer 5. Perform actions completing the logging

Create the Superclass

Logger Algorithm Input: String of text to log 1. Create new file in which results stored 2. If file needs a header to be correct 1. Print out the file header 3. Print out the text to the file 4. If file trailer is needed for correctness 1. Print out the file trailer 5. Perform actions completing the logging

Logger Superclass final public abstract class Logger { public final void logIt(String text){ File log = createLogFile(); if (needsHeader()) { printHeader(log); } logText(log, text); if (needsTrailer()) { printTrailer(log); } completeLog(log); }

Should Method be Hook?  If method’s steps known & cannot be changed  Subclasses do not need to define it at all  Can define this as private method in superclass  Include code directly and do not make abstract  If the action is optional or usually works 1 way  Define simple/empty method in superclass  DO NOT MAKE FINAL  DO NOT MAKE FINAL ; subclasses may override  If you have no clue how method works  Leave for subclasses; make method abstract

Hooks in Logger public abstract class Logger { public final void logIt(String text){ File log = createLogFile(); if (needsHeader()) { printHeader(log); } logText(log, text); if (needsTrailer()) { printTrailer(log); } completeLog(log); }

Bring Out the Hook public abstract class Logger { public boolean needsHeader() { return false; } public boolean needsTrailer() { return false; } public void printHeader(File log){ } public void printTrailer(File log){ } }

Define the Hook public class HTMLLogger extends Logger { public boolean needsHeader() { return true; } public void printHeader(File log){ PrintWriter w = new PrintWriter(log); w.println(“ ”); } // Similar code for trailer methods

Think of the Children! public abstract class Logger { public final void logIt(String text){ File log = createLogFile(); if (needsHeader()) { printHeader(log); } logText(log, text); if (needsTrailer()) { printTrailer(log); } completeLog(log); }

Today’s Activity

Template Method Pattern public abstract class Activity { public final void makeEmWork() { doSomething(); discussProblem(); doSomethingElse(); Mug m = getMug(); doSomethingMore(m); solveProblem(m); concludeSomething(); }

For Next Class  Lab due next Friday, so get cracking  When we return discuss tree-based design pattern  Have a great Easter break!