🗊 Презентация Introduction to Programming

Нажмите для полного просмотра!
Introduction to Programming, слайд №1 Introduction to Programming, слайд №2 Introduction to Programming, слайд №3 Introduction to Programming, слайд №4 Introduction to Programming, слайд №5 Introduction to Programming, слайд №6 Introduction to Programming, слайд №7 Introduction to Programming, слайд №8 Introduction to Programming, слайд №9 Introduction to Programming, слайд №10 Introduction to Programming, слайд №11 Introduction to Programming, слайд №12 Introduction to Programming, слайд №13 Introduction to Programming, слайд №14 Introduction to Programming, слайд №15 Introduction to Programming, слайд №16 Introduction to Programming, слайд №17 Introduction to Programming, слайд №18 Introduction to Programming, слайд №19 Introduction to Programming, слайд №20 Introduction to Programming, слайд №21 Introduction to Programming, слайд №22 Introduction to Programming, слайд №23 Introduction to Programming, слайд №24 Introduction to Programming, слайд №25 Introduction to Programming, слайд №26 Introduction to Programming, слайд №27 Introduction to Programming, слайд №28 Introduction to Programming, слайд №29 Introduction to Programming, слайд №30 Introduction to Programming, слайд №31 Introduction to Programming, слайд №32 Introduction to Programming, слайд №33 Introduction to Programming, слайд №34 Introduction to Programming, слайд №35 Introduction to Programming, слайд №36 Introduction to Programming, слайд №37 Introduction to Programming, слайд №38 Introduction to Programming, слайд №39 Introduction to Programming, слайд №40 Introduction to Programming, слайд №41

Содержание

Вы можете ознакомиться и скачать презентацию на тему Introduction to Programming. Доклад-сообщение содержит 41 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1


Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3
Описание слайда:
Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3

Слайд 2


Today We will revisit classes, features and objects. We will see how program execution starts. We will play a game.
Описание слайда:
Today We will revisit classes, features and objects. We will see how program execution starts. We will play a game.

Слайд 3


Static view A program consists of a set of classes. Features are declared in classes. They define operations on objects constructed from the class....
Описание слайда:
Static view A program consists of a set of classes. Features are declared in classes. They define operations on objects constructed from the class. Queries answer questions. They have a result type. Commands execute actions. They do not have a result type. Terms “class” and “type” used interchangeably for now.

Слайд 4


Dynamic view At runtime we have a set of objects (instances) constructed from the classes. An object has a type that is described in a class. Objects...
Описание слайда:
Dynamic view At runtime we have a set of objects (instances) constructed from the classes. An object has a type that is described in a class. Objects interact with each other by calling features on each other.

Слайд 5


Static view vs. dynamic view Queries (attributes and functions) have a return type. However, when executing the query, you get an object. Routines...
Описание слайда:
Static view vs. dynamic view Queries (attributes and functions) have a return type. However, when executing the query, you get an object. Routines have formal arguments of certain types. During the execution you pass objects as actual arguments in a routine call. During the execution local variables declared in a routine are objects. They all have certain types.

Слайд 6


Declaring the type of an object The type of any object you use in your program must be declared somewhere. Where can such declarations appear in a...
Описание слайда:
Declaring the type of an object The type of any object you use in your program must be declared somewhere. Where can such declarations appear in a program? in feature declarations formal argument types return type for queries in the local clauses of routines

Слайд 7


Declaring the type of an object class DEMO feature procedure_name (a1: T1; a2, a3: T2) -- Comment local l1: T3 do … end function_name (a1: T1; a2,...
Описание слайда:
Declaring the type of an object class DEMO feature procedure_name (a1: T1; a2, a3: T2) -- Comment local l1: T3 do … end function_name (a1: T1; a2, a3: T2): T3 -- Comment do … end attribute_name: T3 -- Comment end

Слайд 8


Exercise: Find the classes / objects class game feature map_name: string -- Name of the map to be loaded for the game last_player: player -- Last...
Описание слайда:
Exercise: Find the classes / objects class game feature map_name: string -- Name of the map to be loaded for the game last_player: player -- Last player that moved players: player_list -- List of players in this game. ...

Слайд 9


Exercise: Find the classes / objects feature is_occupied (a_location: traffic_place): boolean -- Check if `a_location' is occupied by some flat...
Описание слайда:
Exercise: Find the classes / objects feature is_occupied (a_location: traffic_place): boolean -- Check if `a_location' is occupied by some flat hunter. require a_location_exists: a_location /= Void local old_cursor: cursor do Result := False -- Remember old cursor position. old_cursor := players.cursor ...

Слайд 10


Exercise: Find the classes / objects -- Loop over all players to check if one occupies -- `a_location'. from players.start -- do not consider estate...
Описание слайда:
Exercise: Find the classes / objects -- Loop over all players to check if one occupies -- `a_location'. from players.start -- do not consider estate agent, hence skip the first -- entry in `players'. players.forth until players.after or Result loop if players.item.location = a_location then Result := True end players.forth end -- Restore old cursor position. players.go_to(old_cursor) end

Слайд 11


Who are Adam and Eve? Who creates the first object? The runtime creates a so called root object. The root object creates other objects, which in turn...
Описание слайда:
Who are Adam and Eve? Who creates the first object? The runtime creates a so called root object. The root object creates other objects, which in turn create other objects, etc. You define the type of the root object in the project settings. You select a creation procedure of the root object as the first feature to be executed.

Слайд 12


Acrobat game We will play a little game now. Everyone will be an object. There will be different roles.
Описание слайда:
Acrobat game We will play a little game now. Everyone will be an object. There will be different roles.

Слайд 13


You are an acrobat When you are asked to Clap, you will be given a number. Clap your hands that many times. When you are asked to Twirl, you will be...
Описание слайда:
You are an acrobat When you are asked to Clap, you will be given a number. Clap your hands that many times. When you are asked to Twirl, you will be given a number. Turn completely around that many times. When you are asked for Count, announce how many actions you have performed. This is the sum of the numbers you have been given to date.

Слайд 14


You are an ACROBAT class ACROBAT feature clap (n: INTEGER) do -- Clap `n’ times and adjust `count’. end twirl (n: INTEGER) do -- Twirl `n’ times and...
Описание слайда:
You are an ACROBAT class ACROBAT feature clap (n: INTEGER) do -- Clap `n’ times and adjust `count’. end twirl (n: INTEGER) do -- Twirl `n’ times and adjust `count’. end count: INTEGER end

Слайд 15


You are an acrobat with a buddy You will get someone else as your Buddy. When you are asked to Clap, you will be given a number. Clap your hands that...
Описание слайда:
You are an acrobat with a buddy You will get someone else as your Buddy. When you are asked to Clap, you will be given a number. Clap your hands that many times. Pass the same instruction to your Buddy. When you are asked to Twirl, you will be given a number. Turn completely around that many times. Pass the same instruction to your Buddy. If you are asked for Count, ask your Buddy and answer with the number he tells you.

Слайд 16


You are an ACROBAT_WITH_BUDDY class ACROBAT_WITH_BUDDY inherit ACROBAT redefine twirl, clap, count end create make feature make (p: ACROBAT) do --...
Описание слайда:
You are an ACROBAT_WITH_BUDDY class ACROBAT_WITH_BUDDY inherit ACROBAT redefine twirl, clap, count end create make feature make (p: ACROBAT) do -- Remember `p’ being the buddy. end clap (n: INTEGER) do -- Clap `n’ times and forward to buddy. end

Слайд 17


You are an ACROBAT_WITH_BUDDY twirl (n: INTEGER) do -- Twirl `n’ times and forward to buddy. end count: INTEGER do -- Ask buddy and return his...
Описание слайда:
You are an ACROBAT_WITH_BUDDY twirl (n: INTEGER) do -- Twirl `n’ times and forward to buddy. end count: INTEGER do -- Ask buddy and return his answer. end buddy: ACROBAT end

Слайд 18


You are an author When you are asked to Clap, you will be given a number. Clap your hands that many times. Say “Thank You.” Then take a bow (as...
Описание слайда:
You are an author When you are asked to Clap, you will be given a number. Clap your hands that many times. Say “Thank You.” Then take a bow (as dramatically as you like). When you are asked to Twirl, you will be given a number. Turn completely around that many times. Say “Thank You.” Then take a bow (as dramatically as you like). When you are asked for Count, announce how many actions you have performed. This is the sum of the numbers you have been given to date.

Слайд 19


You are an AUTHOR class AUTHOR inherit ACROBAT redefine clap, twirl end feature clap (n: INTEGER) do -- Clap `n’ times say thanks and bow. end twirl...
Описание слайда:
You are an AUTHOR class AUTHOR inherit ACROBAT redefine clap, twirl end feature clap (n: INTEGER) do -- Clap `n’ times say thanks and bow. end twirl (n: INTEGER) do -- Twirl `n’ times say thanks and bow. end end

Слайд 20


You are a curmudgeon When given any instruction (Twirl or Clap), ignore it, stand up and say (as dramatically as you can) “I REFUSE”. If you are...
Описание слайда:
You are a curmudgeon When given any instruction (Twirl or Clap), ignore it, stand up and say (as dramatically as you can) “I REFUSE”. If you are asked for Count, always answer with 0. Then sit down again if you were originally sitting.

Слайд 21


You are a CURMUDGEON class CURMUDGEON inherit ACROBAT redefine clap, twirl end feature clap (n: INTEGER) do -- Say “I refuse”. end twirl (n: INTEGER)...
Описание слайда:
You are a CURMUDGEON class CURMUDGEON inherit ACROBAT redefine clap, twirl end feature clap (n: INTEGER) do -- Say “I refuse”. end twirl (n: INTEGER) do -- Say “I refuse”. end end

Слайд 22


I am the root object I got created by the runtime. I am executing the first feature.
Описание слайда:
I am the root object I got created by the runtime. I am executing the first feature.

Слайд 23


I am a DIRECTOR
Описание слайда:
I am a DIRECTOR

Слайд 24


Let’s play
Описание слайда:
Let’s play

Слайд 25


I am the root object prepare_and_play local acrobat1, acrobat2, acrobat3 : ACROBAT partner1, partner2: ACROBAT_WITH_BUDDY author1: AUTHOR...
Описание слайда:
I am the root object prepare_and_play local acrobat1, acrobat2, acrobat3 : ACROBAT partner1, partner2: ACROBAT_WITH_BUDDY author1: AUTHOR curmudgeon1: CURMUDGEON do create acrobat1 create acrobat2 create acrobat3 create partner1.make (acrobat1)‏ create partner2.make (partner1)‏ create author1 create curmudgeon1 author1.clap (4)‏ partner1.twirl (2)‏ curmudgeon1.clap (7)‏ acrobat2.clap (curmudgeon1.count)‏ acrobat3.twirl (partner2.count)‏ partner1.buddy.clap (partner1.count)‏ partner2.clap (2) end

Слайд 26


Concepts seen
Описание слайда:
Concepts seen

Слайд 27


Concepts seen
Описание слайда:
Concepts seen

Слайд 28


Advanced Material
Описание слайда:
Advanced Material

Слайд 29


Outline Invariants Marriage problems Violating the invariant
Описание слайда:
Outline Invariants Marriage problems Violating the invariant

Слайд 30


Invariants explained in 60 seconds Consistency requirements for a class Established after object creation Hold, when an object is visible Entry of a...
Описание слайда:
Invariants explained in 60 seconds Consistency requirements for a class Established after object creation Hold, when an object is visible Entry of a routine Exit of a routine class ACCOUNT feature balance: INTEGER invariant balance >= 0 end

Слайд 31


Public interface of person (without contracts) class PERSON feature spouse: PERSON -- Spouse of Current. marry (a_other: PERSON) -- Marry `a_other’....
Описание слайда:
Public interface of person (without contracts) class PERSON feature spouse: PERSON -- Spouse of Current. marry (a_other: PERSON) -- Marry `a_other’. end

Слайд 32


Write the contracts class PERSON feature spouse: PERSON marry (a_other: PERSON) require ?? ensure ?? invariant ?? end
Описание слайда:
Write the contracts class PERSON feature spouse: PERSON marry (a_other: PERSON) require ?? ensure ?? invariant ?? end

Слайд 33


A possible solution class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void ensure...
Описание слайда:
A possible solution class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void ensure spouse = a_other a_other.spouse = Current end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 34


Implementing marry class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do ??...
Описание слайда:
Implementing marry class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do ?? ensure spouse = a_other a_other.spouse = Current end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 35


Implementing marry I class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do...
Описание слайда:
Implementing marry I class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do a_other.spouse := Current spouse := a_other ensure spouse = a_other a_other.spouse = Current end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 36


Implementing marry II class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do...
Описание слайда:
Implementing marry II class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do a_other.set_spouse (Current) spouse := a_other ensure spouse = a_other a_other.spouse = Current end set_spouse (a_person: PERSON) do spouse := a_person end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 37


Implementing marry III class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do...
Описание слайда:
Implementing marry III class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do a_other.set_spouse (Current) spouse := a_other ensure spouse = a_other a_other.spouse = Current end feature {PERSON} set_spouse (a_person: PERSON) do spouse := a_person end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 38


Implementing marry : final version class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse =...
Описание слайда:
Implementing marry : final version class PERSON feature spouse: PERSON marry (a_other: PERSON) require a_other /= Void a_other.spouse = Void spouse = Void do spouse := a_other a_other.set_spouse (Current) ensure spouse = a_other a_other.spouse = Current end feature {PERSON} set_spouse (a_person: PERSON) do spouse := a_person end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 39


Ending the marriage class PERSON feature spouse: PERSON divorce require spouse /= Void do spouse.set_spouse (Void) spouse := Void ensure spouse =...
Описание слайда:
Ending the marriage class PERSON feature spouse: PERSON divorce require spouse /= Void do spouse.set_spouse (Void) spouse := Void ensure spouse = Void (old spouse).spouse = Void end invariant spouse /= Void implies spouse.spouse = Current end

Слайд 40


Violating the invariant See demo
Описание слайда:
Violating the invariant See demo

Слайд 41


What we have seen Invariant should only depend on Current object If invariant depends on other objects Take care who can change state Take care in...
Описание слайда:
What we have seen Invariant should only depend on Current object If invariant depends on other objects Take care who can change state Take care in which order you change state Invariant can be temporarily violated You can still call features on Current object Take care calling other objects, they might call back Although writing invariants is not that easy, they are necessary to do formal proofs. This is also the case for loop invariants (which will come later).



Похожие презентации
Mypresentation.ru
Загрузить презентацию