Computer Science 313 – Advanced Programming Topics.

Slides:



Advertisements
Similar presentations
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Advertisements

Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
Computer Science 313 – Advanced Programming Topics.
Computer Science 313 – Advanced Programming Topics.
CS 206 Introduction to Computer Science II 09 / 24 / 2008 Instructor: Michael Eckmann.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis 1.
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:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
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.
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.
CIS101 Introduction to Computing Week 12 Spring 2004.
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
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.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
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.
Computer Science 111 Fundamentals of Programming I The while Loop and Indefinite Loops.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 14.
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.
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.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
 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.
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.
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
Instructor: Alexander Stoytchev
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

For Next Class  Lab due in about 1 hour  Reports due Monday after break  Will be useful for Test#2 week after we get back  Have a fun Spring Break!