1 Advanced Material The following slides contain advanced material and are optional.

Slides:



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

Semantics Static semantics Dynamic semantics attribute grammars
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 10: Advanced Object-Oriented Mechanisms (based on.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
2 nd Microsoft Rotor Workshop, Pisa, April 23-25, SCOOPLI for.NET: a library for concurrent object-oriented programming Volkan Arslan, Piotr Nienaltowski.
Chair of Software Engineering Constants, once routines, and helper functions these slides contain advanced material and are optional.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Eiffel examples. Example 1 class C creation default_create feature {ANY} -- the public class data count: INTEGER element: DOUBLE end; features - the data.
VBA Modules, Functions, Variables, and Constants
-5- Exception handling What is an exception? “An abnormal event” Not a very precise definition Informally: something that you don’t want to happen.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 9: Contracts and Inheritance (based on work with.
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
1 Advanced Material The following slides contain advanced material and are optional.
Ranga Rodrigo. Class is central to object oriented programming.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
10 Conversion. Let’s start with conformance Conformance determines when a type may be used in lieu of another. Conformance relies on inheritance. The.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
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.
Contract based programming Using pre- and post-conditions, and object invariants Contract based programming1.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
More About Classes Ranga Rodrigo. Information hiding. Copying objects.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Contracts for Concurrency - Contracts & Inheritance Aryabrata Basu University of Georgia.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Programming in Java CSCI-2220 Object Oriented Programming.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 4.
Chapter 3 Part II Describing Syntax and Semantics.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
(3-1) Functions II H&K Chapter 3 Instructor - Andrew S. O’Fallon CptS 121 (September 9, 2015) Washington State University.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Ceg860 (Prasad)L17IT1 Inheritance Techniques Subcontracting Anchored Types.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
1 Contractual Consistency Between BON Static and Dynamic Diagrams Ali Taleghani July 30, 2004.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Scheme in Scheme 2. What’s next  Adding set!  Dynamic vs. lexical variable scope  Extending mcscheme v1 with libraries  Can mcscheme execute mcscheme?
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
1 Exceptions When the Contract is Broken. 2 Definitions A routine call succeeds if it terminates its execution in a state satisfying its contract A routine.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
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 Void safety these slides contain advanced material and are optional.
CS314 – Section 5 Recitation 9
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Introduction to the C Language
Topics: jGRASP editor ideosyncrasies assert debugger.
Chapter 7 - JavaScript: Introduction to Scripting
Mini Language Interpreter Programming Languages (CS 550)
The following slides contain advanced material and are optional.
JavaScript: Introduction to Scripting
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Graph Coverage for Design Elements CS 4501 / 6501 Software Testing
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
8 Once features.
Once features.
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

1 Advanced Material The following slides contain advanced material and are optional.

2 Outline  Constants and global variables  Constants in OO programming  Once routines  Definition  Use  Sharing objects  Arguments and contracts

3 Constants and global variables  Constants for basic types are easy class CONSTANTS Pi: Real = Ok: Boolean = True Message: STRING = “abc” end class APPLICATION inherit CONSTANTS feature foo do print (Pi) end end

4 Constants in OO programs  What about user defined types? class CONSTANTS i: COMPLEX = ??? Hans: PERSON = ??? Paris: MAP = ??? end  In other languages  Static variables  Singleton pattern  In Eiffel  Once routines

5 What are once routines?  Executed the first time  Result is stored  In further calls, stored result is returned foo: INTEGER once Result := factorial (10) end test_foo do io.put_integer (foo) , calculated io.put_integer (foo) , directly returned end

6 Once for whom?  By default, computation is once per class hierarchy  Result is shared among all objects of a class and its subclasses  Once routines can take a special flag  This flag is used to indicate that execution is e.g. one of  Once per object  Once per thread

7 Use of once routines  Constants, other than basic types i: COMPLEX once create Result.make (0, 1) end  Lazy initialization settings: SETTINGS once create Result.load_from_filesystem end  Initialization procedures init_graphics_system once... end  Sharing of objects (see next)

8 Sharing objects I  You can share objects  Can be used to achieve effect of global/static variables  How?  Once routine returning a reference  Will always return the same reference  Create a SHARED_X class and inherit from it

9 Sharing objects II class SHARED_X the_one_and_only_x: attached X once create Result.make end class X create {SHARED_X} make feature {NONE} make do end

10 Pitfalls of once and constants  No guarantee that only one instance will be created  Inheriting classes can also call creation routine  Problems can arise when once references are shared with external C code due to the garbage collector  Strings are not expanded! message: STRING = “abc” foo do message.append (“def”) -- from now, “message” will be “abcdef” end

11 Arguments and contracts foo (i: INTEGER): INTEGER require i > 0 once Result := i * 2 ensure Result = i * 2 end  What is the output of the following code block do io.put_integer (foo (2)) io.put_integer (foo (3)) io.put_integer (foo (-2)) end Don‘t write once functions taking arguments. Don‘t write complex postconditions in once funcions postcondition violation -- precondition violation

12 A peek at the Eiffel ECMA specification – Semantics: General Call Semantics The effect of an Object_call of feature sf is, in the absence of any exception, the effect of the following sequence of steps: 1.Determine the target object O through the applicable definition. 2.Attach Current to O. 3.Determine the dynamic feature df of the call through the applicable definition. 4.For every actual argument a, if any, in the order listed: obtain the value v of a; then if the type of a converts to the type of the corresponding formal in sf, replace v by the result of the applicable conversion. Let arg_values be the resulting sequence of all such v. 5.Attach every formal argument of df to the corresponding element of arg_values by applying the Reattachment Semantics rule. 6.If the call is qualified and class invariant monitoring is on, evaluate the class invariant of O’s base type on O. 7.If precondition monitoring is on, evaluate the precondition of df. 8.If df is not an attribute, not a once routine and not external, apply Non-Once Routine Execution Semantics to O and df. 9.If df is a once routine, apply the Once Routine Execution Semantics to O and df. 10.If df is an external routine, execute that routine on the actual arguments given, if any, according to the rules of the language in which it is written. 11.If the call is qualified and class invariant monitoring is on, evaluate the class invariant of O’s base type on O. 12.If postcondition monitoring is on, evaluate the postcondition of df.