28-Oct-15 Information Hiding A very short talk. Modularization Whenever a program is broken into two parts, there comes into being an interface between.

Slides:



Advertisements
Similar presentations
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Advertisements

User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
1 CSC 221: Computer Programming I Fall 2006 interacting objects modular design: dot races constants, static fields cascading if-else, logical operators.
Lectures 10 & 11.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
Kathleen Fisher cs242 Reading: “A history of Haskell: Being lazy with class”,A history of Haskell: Being lazy with class Section 6.4 and Section 7 “Monads.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
1 Chapter Eight Designing Libraries. 2 Programming Complexity As long as we continue to solve problems of ever-increasing sophistication, the process.
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
Passing Arguments Suppose you’re seated in class, which doesn’t begin for another 20 minutes… …and your friend, who missed the last two classes due to.
Procedures and Control Flow CS351 – Programming Paradigms.
1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)
Time Capsule. It can tell us the time we live in.
CSE341: Programming Languages Lecture 12 Equivalence Dan Grossman Spring 2013.
Software Engineering and Design Principles Chapter 1.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
1 CS 410 Mastery in Programming Chapter 4 Side Effects Herbert G. Mayer, PSU CS status 7/9/2011.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
23-Jun-15 Unit Testing in Ruby. Programming methodologies The grim facts: The majority of large programming projects fail Projects that succeed are usually.
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
26-Jun-15 Methods. About methods A method is a named group of declarations and statements If a method is in the same class, you execute those declarations.
1 Overloading functions C++ allows us to define functions that have the same name but different sets of parameters This capability can be used to define.
CSE1301 Computer Programming: Lecture 29 Group Project: “Quabble”
Computer Science 1620 Lifetime & Scope. Variable Lifetime a variable's lifetime is finite Variable creation: memory is allocated to the variable occurs.
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Early Design Process Brent M. Dingle, Ph.D Game Design and Development Program Mathematics, Statistics and Computer Science University of Wisconsin.
Lists. Lists store information in a certain order. You can add, remove, or rearrange items in a list. You can also pick out information from a list.
CS161 Topic #15 1 Today in CS161 Lecture #15 Practicing! Writing Programs to Practice Write a game program (1 player) of Mad Math Reuse the functions to.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Software Design 4.1 Tell, Don't Ask l Tell objects what you want them to do, do not ask questions about state, make a decision, then tell them what to.
CSE 219 Computer Science III Program Design Principles.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Programming Principles Chapter 1. Objectives Discuss the program design process. Introduce the Game of Life. Discuss object oriented design. – Information.
Slide 1 Unit Testing. Slide 2 Unit Testing Options l Use N-Unit In a microsoft environment.NET… you can use their supplied N-Unit testing to test your.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
Learners Support Publications Functions in C++
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
18-1 Queues Data Structures and Design with Java and JUnit © Rick Mercer.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions Lecture 12.
What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
Method Parameters and Overloading Version 1.0. Topics The run-time stack Pass-by-value Pass-by-reference Method overloading Stub and driver methods.
Functions Functions, locals, parameters, and separate compilation.
Guide to Programming with Python Chapter Six Functions: The Tic-Tac-Toe Game.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Passing Function Arguments by Reference : A Sample Lesson for CS 1 using the C Programming Language Andy D. Digh Friday, May 29th, 1998.
1 Functions Part 1 Prototypes Arguments Overloading Return values.
Unit Testing CLUE PLAYERS.  How much design do we do before we begin to code?  Waterfall: Design it all! (slight exaggeration… but not much)  Agile:
CS 265 Jianbo Zhao. What is interface? Interface is a detailed boundary between code that provides a service and code that uses it. An interface defines.
User-Written Functions
More Sophisticated Behavior
Review What is an object? What is a class?
Functions, locals, parameters, and separate compilation
CS1061 C Prgramming Lecture 11: Functions
Information Hiding Example
Lesson 2: Building Blocks of Programming
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
CMSC 202 Lesson 22 Templates I.
Information Hiding Example
In C Programming Language
Templates I CMSC 202.
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
HFOOAD Chapter 5 Interlude
Functions and Abstraction
Presentation transcript:

28-Oct-15 Information Hiding A very short talk

Modularization Whenever a program is broken into two parts, there comes into being an interface between them: The parameter list Any global or common More subtle ways of information transmission This interface should be kept as narrow and as explicit as possible. How to make it narrow? Have each method do only one thing Be able to describe what it does without saying “but” or “except” Keep parameter lists short Avoid global variables How to make it explicit? Avoid global variables Avoid side effects

Information hiding The principle of information hiding is, informally, Every method should mind its own business To use a method, you need to know: What information do you need to give it? What does it tell you (or do for you) in return? You do not need to know: How it does its job The method should not need to know: How you do your job

What’s wrong with these? int max (int size, int a[]) { sort (a, size); return a[0]; int max (int size, int a[]) { int i; temp = a[0]; for (i = 1; i temp) temp = a[i]; return temp; } int max (int size, int a[]) { int i, temp; temp = 0; for (i = 0; i temp) temp = a[i]; return temp; }

A reasonably good program void play() { setup(); player = who_goes_first(); do { if (player == HUMAN) { do { move = get_humans_move(); } while !legal(move); game_over = make_move(HUMAN, move); player = COMPUTER; } else { /* player == COMPUTER */ move = choose_computers_move(); game_over = make_move(COMPUTER, move); player = HUMAN; } } while(!game_over); }

A not-so-good program What routine or routines update player ? Do they do it in such a way that the main program works? If the human's move is not ok, has player already been updated? How does make() know whose move to make? Who sets ok ? When does the game end? Who's responsible for deciding this? Is movecounter being initialized properly? Computed properly? What is it anyway, and who uses it? void play() { setup(); player = who_goes_first(); do { if (player == HUMAN) { do { move = get_humans_move(); check_if_legal(move); movecounter++; } while(!ok); make_move(move); } else { /* player == COMPUTER */ move = choose_computers_move(); make_move(move); } } while (!game_over); }

Test-Driven Development (TDD) It is difficult to add JUnit tests to an existing program The program probably wasn’t written with testing in mind It’s actually better to write the tests before writing the code you want to test When tests are written first, you have a clearer idea what to do when you write the methods Because the tests are written first, the methods are necessarily written to be testable Writing tests first encourages you to write simpler, single-purpose methods Because the methods will be called from more than one environment (the “real” one, plus your test class), they tend to be more independent of the environment

The End