Lab1 Lab 1: CSG 711: Programming to Structure Karl Lieberherr.

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Lab1 Lab 1: CSG 711: Programming to Structure Karl Lieberherr.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
History of Object Orientation. What is Object-Orientation? Programming is one of the most complicated and difficult of human activities. It helps a great.
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
Basic Mathematical Models; Direction Fields. A Falling Object.
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:
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Chapter 2: Algorithm Discovery and Design
CS 201 Functions Debzani Deb.
Topic 6 Generic Data Structures "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Programming 2 LAB TA: Nouf Al-Harbi NoufNaief.net :::
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Getting a New Behavior to Occur: An Application of Shaping
MVC pattern and implementation in java
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Recursion Pepper. Recursion Definition English –procedure that can repeat a version of itself indefinitely – such as mirrors looking at each other. Math.
Recursion Pepper. Another way to loop Call yourself repeatedly until you say to stop. Example: add up 10 numbers using addUp. -- Input – number to count.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Object Oriented Programming
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Generic Data Structures "Get your data structures correct first, and the rest of the program will write itself." - David Jones EE 422CGenerics 1.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
The DD  OO Recipe CS 5010 Program Design Paradigms "Bootcamp" Lesson 10.4 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Error Example - 65/4; ! Toplevel input: ! 65/4; ! ^^ ! Type clash: expression of type ! int ! cannot have type ! real.
Advanced Software Development Karl Lieberherr CSG 260 Fall Semester
1.7 Linear Independence. in R n is said to be linearly independent if has only the trivial solution. in R n is said to be linearly dependent if there.
Lab 11 Lab 1: CSG 711: Programming to Structure Karl Lieberherr.
Interpreters and Higher-Order Functions CSE 413 Autumn 2008 Credit: CSE341 notes by Dan Grossman.
Functions vs. Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Virtual Functions Outline 20.1Introduction 20.2Type Fields and switch Statements 20.3Virtual.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
Access Test Solutions Fall 2014 Questions 7 and 8 Karl Lieberherr.
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
1 Chapter 9 Introduction to Classes and Objects Program Development and Design Using C++, Third Edition.
Software Engineering Algorithms, Compilers, & Lifecycle.
Programming Languages Dan Grossman 2013
Programming what is C++
Programming Languages Dan Grossman 2013
Inheritance ITI1121 Nour El Kadri.
INF3110: Exercises Part 6 Object Orientation Comments and solutions
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.3
Lecture 5 Dr. Nermin Hamza.
Topic 6 Generic Data Structures
Hello World 2 What does all that mean?.
Object-Oriented Programming
Week 6 Object-Oriented Programming (2): Polymorphism
Object-Oriented Programming
Overview of Programming Paradigms
Object-Oriented Programming
INF3110: Exercises Part 6 Object Orientation Comments and solutions
SPLITTING OF COMBINED SHAPES
Area of combined figures
Can you work out the next shape in the pattern?
Inheritance Lakshmish Ramaswamy.
Can you work out the next shape in the pattern?
Presentation transcript:

Lab1 Lab 1: CSG 711: Programming to Structure Karl Lieberherr

Lab2 History Frege: Begriffsschrift 1879: “The meaning of a phrase is a function of the meanings of its immediate constituents.” Example: AppleList : Mycons | Myempty. Mycons = Apple AppleList. Apple = int. Myempty =.

Lab3 Meaning of a list of apples? Total weight (tWeight al) –[(Myempty? al) 0] –[(Mycons? al) (Apple-weight(Mycons-first al)) // meaning of first constituent + (tWeight(Mycons-rest al))] // meaning of rest constituent AppleList : Mycons | Myempty. Mycons = Apple AppleList. Apple = int. Myempty =. PL independent AppleList Mycons Myempty Apple int rest first weight

Lab4 In Scheme: Structure (define-struct Mycons (first rest)) (define-struct Apple (weight)) (define-struct Myempty ())

Lab5 Design Information AppleList : Mycons | Myempty. Mycons = Apple AppleList. Apple = int. Myempty =. AppleList Mycons Myempty Apple int rest first weight Scheme solution Mycons Myempty Apple int rest first weight (define-struct Mycons (first rest)) (define-struct Apple (weight)) (define-struct Myempty ())

Lab6 In Scheme: Behavior (define (tWeight al) (cond [(Myempty? al) 0] [(Mycons? al) (+ (Apple-weight (Mycons-first al)) (tWeight (Mycons-rest al)))]))

Lab7 In Scheme: Testing (define list1 (make-Mycons (make-Apple 111) (make-Myempty))) (tWeight list1) 111 (define list2 (make-Mycons (make-Apple 50) list1)) (tWeight list1) 161

Lab8 Reflection on Scheme solution Program follows structure Design translated somewhat elegantly into program. Dynamic programming style. But the solution has problems!

Lab9 Structure The Scheme program has lost information that was available at design time. –The first line is missing. –Scheme allows us to put anything into the fields. AppleList : Mycons | Myempty. Mycons = Apple AppleList. Apple = int. Myempty =.

Lab10 Information can be expressed in Scheme Dynamic tests Using object system

Lab11 Behavior While the purpose of this lab is programming to structure, the Scheme solution uses too much structure! (define (tWeight al) (cond [(Myempty? al) 0] [(Mycons? al) (+ (Apple-weight (Mycons-first al)) (tWeight (Mycons-rest al)))])) duplicates all of it!

Lab12 How can we reduce the duplication of structure? First small step: Express all of structure in programming language once. Eliminate conditional! Implementation of tWeight() has a method for Mycons and Myempty. Extensible by addition not modification. Big win of OO.

Lab13 Solution in Java AppleList: abstract int tWeight(); Mycons: int tWeight() { return (first.tWeight() + rest.tWeight()); } Myempty: int tWeight() {return 0;} AppleList : Mycons | Myempty. Mycons = Apple AppleList. Apple = int. Myempty =. + translated to Java

Lab14 What is better? structure-shyness has improved. No longer enumerate alternatives in functions. Better follow principle of single point of control (of structure).

Lab15 Problem to think about (while you do hw 1) Consider the following two Shape definitions. –in the first, a combination consists of exactly two shapes. –in the other, a combination consists of zero or more shapes. Is it possible to write a program that works correctly for both shape definitions?

Lab16 First Shape Shape : Rectangle | Circle | Combination. Rectangle = "rectangle" int int int int. Circle = "circle" int int int. Combination = "(" Shape Shape ")".

Lab17 Second Shape Shape : Rectangle | Circle | Combination. Rectangle = "rectangle" int int int int. Circle = "circle" int int int. Combination = "(" List(Shape) ")". List(S) ~ {S}.

Lab18 Input (for both Shapes) ( rectangle ( circle rectangle )

Lab19 Abstractions abstraction through parameterization: – planned modification points aspect-oriented abstractions: –unplanned extension points