Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 12 28. October 2008.

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Advertisements

Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session November 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Function Overloading Having more than one function with the same name. list of argument of a function are called signature of a function. We can have more.
Chair of Software Engineering Object-Oriented Software Construction Bertrand Meyer Lesson 16 Last update: 25 May 2004 An O-O design example.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 12: More on references and.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 4: Objects.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 2 23 September 2008.
Chair of Software Engineering ATOT - Lecture 17, 28 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 3 29 September 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 12: More on references and.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
Chair of Software Engineering ATOT - Lecture 23, 23 June Advanced Topics in Object Technology Bertrand Meyer.
Chapter 1 Introduction to C Programming. 1.1 INTRODUCTION This book is about problem solving with the use of computers and the C programming language.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
Introduction to a Programming Environment
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 9.
Chair of Software Engineering ATOT - Lecture 5, 14 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Ranga Rodrigo. Class is central to object oriented programming.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING DATA ABSTRACTION Jehan-François Pâris
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
From Problem Statement to Design
Imperative Programming
Module 7: Object-Oriented Programming in Visual Basic .NET
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Lecture 21 CS110 Lecture 2 January 29, 2004 Announcements –hw1 part 1 – due right now –hw1 part 2 – due Tuesday night Questions Agenda –turnin –Object.
Chapter 3 Implementing Classes. Assignment Read 3.1 – 3.5 and take notes complete Self Check Exercises 1-10; Due September 24 th Read 3.6 – 3.8 and take.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
CS61B L03 Building Objects (1)Garcia / Yelick Fall 2003 © UCB  Dan Garcia ( Kathy Yelick  (
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chapter 3 Implementing Classes
Designing Classes Lab. The object that you brought to class Put it in the basket we will exchange them now.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Chapter Three - Implementing Classes
Introduction to the C Language
Einführung in die Programmierung Introduction to Programming Prof. Dr
Einführung in die Programmierung Introduction to Programming Prof. Dr
JAVA CLASSES.
Presentation transcript:

Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008

Chair of Software Engineering News  Mock exam next week  No exercise session on Monday  Two hours on Tuesday (13:15 – 15:00) 2

Chair of Software Engineering Today’s learning goals  Abstraction  Feature kinds  Exporting features 3

Chair of Software Engineering Abstraction  To abstract is to capture the essence behind the details and the specifics  The client is interested in: 4  a set of services that a software module provides, not its internal representation  what a service does, not how it does it class feature  Object-oriented programming is all about finding right abstractions

Chair of Software Engineering Discussing abstractions  What abstractions were used in the currency converter from assignment 5? 5  Why it is better to have classes for CURRENCY and MONEY than to store their values in STRING and REAL variables respectively?  What other features could these classes have? Hands-On

Chair of Software Engineering Inventing more abstractions  Suppose Credit Suisse liked your currency converter and wants you to extend it to a bank information system  They say: “We should be able to create accounts for our customers in francs, euro and dollars. Clients can perform money transfers between difference accounts at the internal exchange rate”  What abstractions will you add to your application? 6 Hands-On ACCOUNT CUSTOMER TRANSFER BANK ? ? ? ?

Chair of Software Engineering Features: the full story 7 Command Query Feature Function No result Feature Memory Computation Client view (specification) ‏ Internal view (implementation) ‏ Returns result Attribute Procedure Memory Computation Routine No result Returns result

Chair of Software Engineering Two kinds of routines  Procedure  from the client’s viewpoint is a command  call is an instruction  Function  from the client’s viewpoint is a query  call is an expression 8

Chair of Software Engineering Two ways to implement balance 9 (BANK_ACCOUNT) deposits withdrawals 800 (BANK_ACCOUNT) deposits withdrawals balance invariant: balance = total (deposits) – total (withdrawals) Which one will you choose and why?

Chair of Software Engineering Uniform access principle  The client is interested in what a service does, not how it does it  It doesn’t matter for the client, whether you store or compute, he just wants to obtain the balance  Features should be accessible to clients the same way, no matter whether they are implemented by storage or computation 10 my_account.balance

Chair of Software Engineering Naming conventions  Names for classes: PASSENGER, STUDENT, NUMERIC, STORABLE  Names for queries: balance, name, first_element, list_of_students  for boolean queries: full, after, is_empty, is_best_choice  Names for commands: run, do_nothing, pimp_my_exersice_session  Composed of English words using underscore  Full English words, but short 11

Chair of Software Engineering How do you like these names? class SOLVE_QUADRATIC_EQUATION feature solve (a, b, c: REAL) do... end get_dscrm (a, b, c): REAL do... end how_many_solutions_there_are: INTEGER first_solution, second_solution: REAL end 12 Hands-On

Chair of Software Engineering I like these more! 13 class QUADRATIC_EQUATION_SOLVER feature solve (a, b, c: REAL) do... end discriminant (a, b, c): REAL do... end solution_count: INTEGER first_solution, second_solution: REAL end

Chair of Software Engineering Exporting features 14  a1. f, a1. g: valid in any client  a1. h: invalid everywhere (including in A’s own text!) ‏  a1. j: valid only in B, C and their descendants (not valid in A!) ‏  a1. m: valid in B, C and their descendants, as well as in A and its descendants Status of calls in a client with a1: A: class A feature f... g... feature {NONE} h, i... feature {B, C} j, k, l... feature {A, B, C} m, n… end

Chair of Software Engineering Compilation error? class PERSON feature name: STRING feature {BANK} account: BANK_ACCOUNT feature {NONE} loved_one: PERSON think do print („Thinking of “ + loved_one.name) end lend_100_franks do loved_one.account.transfer (account, 100) end 15 Hands-On OK: unqualified callOK: exported to all OK: unqualified call Error: not exported to PERSON

Chair of Software Engineering Adding export status 16 class QUADRATIC_EQUATION feature {?} solve (a, b, c: REAL): do... end feature {?} discriminant (a, b, c): REAL do... end feature {?} solution_count: INTEGER feature {?} first_solution, second_solution: REAL end {NONE} Hands-On

Chair of Software Engineering Creation procedures export  For a creation procedure there are two export statuses:  for regular feature callsx.make feature {A, B} make  for creation instructionscreate x.make create {C} make 17

Chair of Software Engineering Creation procedures export class ACROBAT_WITH_BUDDY create {?} set_buddy... feature {?} set_buddy do... end end 18 Hands-On class NUCLEAR_REACTOR create {?} initialize_to_default... feature {?} initialize_to_deafult do... end end {NONE} {NUCLEAR_POWER_PLANT}

Chair of Software Engineering Exporting attributes  Exporting an attribute only means giving read access x.f := 5  Attributes of other objects can be changed only through commands  protecting the invariant  no need for getter functions! 19

Chair of Software Engineering Exporting attributes class TEMPERATURE feature celsius_value, farenheit_value: REAL set_celsius (a_value: REAL) require above_absolute_zero: a_value >= do celsius_value := a_value farenheit_value := 9/5 * celsius_value + 32 end invariant above_absolute_zero: celsius_value >= correspond: farenheit_value = 9/5 * celsius_value + 32 end 20

Chair of Software Engineering Assigners  If you like the syntax x.f := 5 you can declare an assigner for f 21  In class TEMPERATURE celsius_value: REAL assign set_celsuis  In this case t.celsius_value := 36.6 is a shortcut for t.set_celsius (36.6) ... and it won’t break the invariant!