Compsci 100, Fall 2009 3.1 Topdown v Bottomup l Programming is changing our world  Empowering, liberating, equalizing,… l Everything is a bit: all 0’s.

Slides:



Advertisements
Similar presentations
Java Review Interface, Casting, Generics, Iterator.
Advertisements

Written by: Dr. JJ Shepherd
CompSci 100 Prog Design and Analysis II Sept 9, 2010 Prof. Rodger CompSci 100, Fall n  i=1 i.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Unit 031 Interfaces What is an Interface? Interface Declaration Syntax Implementing Interfaces Using Interfaces as Types Interfaces and Inheritance Interfaces.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CPS 100, Spring Conventions in Compsci 100 projects l We want you to concentrate on algorithms and data structures  Not on rendering fonts, interacting.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Java: Chapter 1 Computer Systems Computer Programming II.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
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.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
The Java Programming Language
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Chapter 18 Java Collections Framework
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
CPS 100, Spring Topdown v Bottomup l Programming is changing our world  Empowering, liberating, equalizing,… l Everything is a bit: all 0’s and.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
CompSci 100e 3.1 Plan for the week l Classes and Objects l Model-View-Controller l Maps and Hashing l Upcoming  Towards Algorithm analysis l APTs:  IsomorphicWords,
Session 6 Comments on Lab 3 & Implications of Inheritance.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
CompSci Inheritance and Interfaces  Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape,
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
OOP Basics Classes & Methods (c) IDMS/SQL News
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
CPS What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l.
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Comp1004: Environments The Java Library. Coming up Recap – Encapsulation – Constructors – Loops – Arrays – ArrayList – Iterators The Java Library – Implementation.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Jeff Forbes Owen Astrachan September 8, 2017
Molecular Ball Simulation
PFTD and PFTW Review hashing from intuitive view point, from general viewpoint, from Java 8 viewpoint Try to isolate dependencies on Java, but knowledge.
JAVA COLLECTIONS LIBRARY
Week 6 Discussion Word Cloud.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Java Programming Language
Presentation transcript:

Compsci 100, Fall Topdown v Bottomup l Programming is changing our world  Empowering, liberating, equalizing,… l Everything is a bit: all 0’s and 1’s  From jpg to mp3 to … l It’s about problems! It’s about details!  Should we think about problems to get to the details?  Should we master details before grand thinking? l See Wikipedia on topdown v bottomup designWikipedia on topdown v bottomup design

Compsci 100, Fall Conventions in Compsci 100 projects l We want you to concentrate on algorithms and data structures  Not on rendering fonts, interacting with users  This is important! But not what this course is about l We try to build GUIs or views that facilitate projects  You write the brains, we build the skull/manikin  Our GUI communicates with your code Requires following conventions in interacting code l GUI libraries are similar across languages, but…  Deeper Java specific details than HashMap

Compsci 100, Fall KWIC: Key word in Context Arise, fair sun, and kill the envious moon, Who I. Yet I should kill thee with much cherishing. shortly, for one would kill the other. Thou! why, those twenty could but kill one life. I beg wherefore, villain, didst thou kill my cousin? That villain mean, But 'banished' to kill me- 'banished'? O friar, thou happy. Tybalt would kill thee, But thou slewest cell there would she kill herself. Then gave I heaven finds means to kill your joys with love! l Read file, find word and it’s context, print  Can find all words, but how do we get context?  Loop and look: create context line for each occurrence  See ContextModel.java

Compsci 100, Fall Use KWIC example to motivate study l Dissect and inspect KWIC code to understand conventions  Understand Model and View interaction  Facilitates doing Markov text-generation assignment l Review some basic coding idioms and ideas  Avoiding recomputing same value, readability, modifiability, … l Errors: possible for a method to fail but still work?  See KWIC code when same key occurs twice on a line!

Compsci 100, Fall MVC Example, key-word-in-context l User loads file  Where? Communicate to?  What changes in model?  What happens in view? l User chooses word  Process in Model  Alternatives?  Generate context, display  How to show in any view? Model initialize addView process fillMap justify SimpleView showMessage showError update addModel

Compsci 100, Fall Key Word in Context Explained l For every different word, store where it occurs  love is the 1 st, 3 rd, 50 th, and 1237 th word in the file l This data is kept in a map, key is word, value is ??  How do we generate the data in the map? l Given a word, how do we find its context? How do we format?  All words are in an array, in order  Memory concerns?  Original KWIC paper by Parnas as comparison

Compsci 100, Fall Code Interlude l Examine ContextModel.process  Called when user enters word, parameter is the word  If file already read, we don’t need map, where is this?  Error checking? When and when happens  How does Model communicate back to View? l Examine ContextModel.justify  What is method doing  What is parameter, where was it constructed, issues?  What about ‘magic numbers’, e.g., 30?  What about comments, should we add some?

Compsci 100, Fall KWIC main program/class public class ContextMain { public static void main(String[] args){ ContextModel model = new ContextModel(); SimpleViewer view = new SimpleViewer("Compsci 100 KWIC", "word>"); view.setModel(model); } l What changes in above, e.g., for Markov assignment?  How can view communicate with any model?  View doesn’t change, model does! Requires using a Java interface to capture commonality

Compsci 100, Fall Model View Controller, MVC l Gui is the View and often the controller  Separate user-interaction from updates to data l User loads file, chooses word, …  Model notified, computes, updates view l Model has all the state and knows when it changes  Communicates changes to views (via controller)  Must be initialized, updated, etc. l Very common Design Pattern  Capture common solutions to problems in a context  Iterator, Composite, Decorator seen in Compsci 100

Compsci 100, Fall Convention Summary l Classes start with capital letter and then we have:  They’re public, except nested class? Protected means …  camelCaseForMethods and ForClasses  Ivars, fields, instance variables, mySize, myMap, …  Constants (public static) are ALL_CAPS l Interfaces are IModel, IView, and so on  Not true for standard Java classes, yes for Compsci 100  Don’t need to label methods as abstract, but can l Supply AbstractDefault implements IThing  Constructor, some state, some common behavior: extend!

Compsci 100, Fall Eugene (Gene) Myers l Lead computer scientist/software engineer at Celera Genomics, then at Berkely, now at Janelia Farms Research Institute (HHMI) l BLAST and WG-Shotgun "What really astounds me is the architecture of life. The system is extremely complex. It's like it was designed." … "There's a huge intelligence there.”

Compsci 100, Fall Methods, Interfaces, Inheritance l A method by any other name would smell as sweet  Method in OO languages, functions, procedures in others  Parameters and return value: communication Do objects or methods communicate?: OO v procedural Static : Math.sqrt, Character.isUpperCase, …  Don’t belong to an object, invoked via class (clue above?)  Java API helpful here l Interface: implement class with required, related methods  HashMap, TreeMap  ArrayList, LinkedList, Vector

Compsci 100, Fall Interfaces continued l In the beginning  Make code work, don’t worry about generalizing  But, if you write code using Map rather than TreeMap Can swap in a new implementation, coded generally! l Don’t know how to optimize: space or time  Facilitate change: use interface rather than concrete class  My DVD connects to my TV, regardless of brand, why?  How do you turn on a Nokia cell phone? Motorola? But! l Interfaces facilitate code refactoring  Don’t add functionality, change speed or memory or …

Compsci 100, Fall What does Object-Oriented mean? l Very common method of organizing code  Design classes, which encapsulate state and behavior  Some classes can be similar to, but different from their parent class: inheritance Super class, subclass  Inherit behavior, use as is or modify and use or both l Complex to design a hierarchy of classes, but important  More of this in Compsci 108 or on-the-job training  We’re solving simple problems, not designing re-usable libraries l Simple does not mean straight-forward, not Vista!

Compsci 100, Fall Inheritance and Interfaces l Interfaces provide method names and parameters  The method signature we can expect and thus use!  What can we do to an ArrayList? To a LinkedList?  What can we do to a Map or Set or PriorityQueue?  java.util.Collection is an interface l Abstract classes can implement core, duplicated code  If we can add one object to a [set,map,list], can we add an entire list of objects? java.util.AbstractCollection  If we can iterate can we remove? Convert to array? Obtain size?

Compsci 100, Fall Random Java stuff l What happens when you call new, when do you?  Creates object, assign reference/pointer somewhere (or?)  Two ‘labels/variables’ share same object, consequences? Why isn’t this a concern with String objects/labels? l What about int, double, byte, char, long  Related, but different. What’s the same, what’s different?  Range of values for each?  Arithmetic with each?  Casting vs promotion (pass int to Math.sqrt?)