chair of software engineering -...
TRANSCRIPT
![Page 1: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/1.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
1
Chair of Software Engineering
Last update: 2 November 2004
Trusted Components
Reuse, Contracts and Patterns
Prof. Dr. Bertrand MeyerDr. Karine Arnout
![Page 2: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/2.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
2
Chair of Software Engineering
Lecture 26: Component model:The .NET example
![Page 3: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/3.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
3
Chair of Software Engineering
Agenda for today
What is .NET?C# basicsEiffel for .NET
![Page 4: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/4.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
4
Chair of Software Engineering
What .NET is not?
NOT a programming language:“C# is not .NET and .NET is not C#”
NOT an operating system (yet).
![Page 5: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/5.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
5
Chair of Software Engineering
What .NET is…
An open-language platform for enterprise and Web development.
![Page 6: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/6.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
6
Chair of Software Engineering
The scope of .NET
.NET addresses almost everyone:The general public
New user-friendly servicesBusinesses
Help improve “B2B” relationships.Developers
SecurityProgramming-language interoperabilityComponent-based developmentVersioningMemory management
![Page 7: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/7.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
7
Chair of Software Engineering
The .NET architecture
UDDI, WSDL, PassportWeb services
XML & SOAPOpen interchange formats
ASP.NET, Windows Forms, Remoting…Frameworks & libraries
C#, Visual Basic.Net, Managed C++, Cobol, Eiffel for .NET…Specific language compilers
Common Language Specification (CLS)Language interoperability
Visual Studio.NetDevelopment environment
Common Language Runtime (CLR)Compilation, execution…
Hardware, Operating system, database systemUnderlying platform
![Page 8: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/8.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
8
Chair of Software Engineering
The Common Language Runtime
Basic set of mechanisms to execute .NET programs.Virtual machine based on internal code: MSIL.MSIL: not interpreted but “jitted” to native platform.Built-in security mechanisms.
![Page 9: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/9.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
9
Chair of Software Engineering
The .NET execution model
![Page 10: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/10.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
10
Chair of Software Engineering
.NET specific vocabulary
Managed code: Native code for the target platform, intended to run under the control and with the help of the CLR.
Ex: C#, Eiffel for .NET, Managed C++
Unmanaged code: Native code that doesn’t rely on the CLR.
Ex: “Classic” Eiffel, Unmanaged C++
![Page 11: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/11.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
11
Chair of Software Engineering
The assembly
Compiled form of a set of classesThe .NET unit of reuse (“.exe” or “.dll”)May be shared or private.
Notion of Global Assembly Cache Contain:
MSIL code (not binary code)Metadata (interface information)
Can be viewed with ILDasm.
![Page 12: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/12.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
12
Chair of Software Engineering
The Global Assembly Cache
![Page 13: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/13.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
13
Chair of Software Engineering
.NET core assembly (mscorlib.dll)
![Page 14: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/14.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
14
Chair of Software Engineering
.NET libraries (1/2)
Namespace What for?System Basic types: Int32, String …
System.Collections Collection types: ArrayList…
System.Data Relational database management
System.Net Network communications
System.Security Security features
System.Runtime.Remoting Distributed computing
System.Drawing GDI graphics
![Page 15: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/15.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
15
Chair of Software Engineering
.NET libraries (2/2)
Namespace What for?System.Text ASCII, Unicode, etc. encoding
System.Threading Thread support
System.Timers Raising time-controlled events
System.Text.RegularExpressions Regular expressions handling
System.Web.UI.WebControls Graphical Web controls
System.Windows.Forms Graphical controls: Button…
→ See the Reference documentation for more information.
![Page 16: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/16.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
16
Chair of Software Engineering
Towards new services…
A (demo) conference registration page
![Page 17: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/17.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
17
Chair of Software Engineering
Successful registration
![Page 18: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/18.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
18
Chair of Software Engineering
Passing erroneous data
![Page 19: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/19.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
19
Chair of Software Engineering
About this demo…
Some of what this demo illustrates:ASP.NET (Active Server Pages .NET)Server-side mechanisms, server controlsDebugging Web applications like traditional onesOur first C# example…Multi-language development (C#, Eiffel for .NET)
![Page 20: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/20.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
20
Chair of Software Engineering
The ASP.NET source
![Page 21: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/21.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
21
Chair of Software Engineering
Multi-language support
C++ C# Eiffel
Framework
...
Windows
![Page 22: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/22.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
22
Chair of Software Engineering
Languages on .NET (1/3)
“Microsoft languages”Visual Basic.NetC#Managed C++Jscript
Commercial languages (see next)Research languages (see next)
![Page 23: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/23.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
23
Chair of Software Engineering
Languages on .NET (2/3)
Commercial offerings from 3rd parties:Cobol (Fujitsu)Eiffel for .NET (Eiffel Software)Smalltalk (QKS)Java (JUMP program)Perl, Python (ActiveState)APL (Dyadic)Fortran (Fujitsu)Fortran (Salford Software)
![Page 24: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/24.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
24
Chair of Software Engineering
Languages on .NET (3/3)
Research languages:CAML (INRIA)Mercury (Melbourne Uni.)SchemeOberon (ETH, Zürich)Component Pascal (QUT)Haskell (Universities, Microsoft Research UK)
![Page 25: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/25.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
25
Chair of Software Engineering
Full interoperability
Cross-language…Inheritance
Classes can inherit from each other, regardless of language of origin.No need for wrappersNo IDL
Debugging sessions In Visual Studio.Net
Exceptions
![Page 26: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/26.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
26
Chair of Software Engineering
Full interoperability: the price to pay…
Must conform to the .NET object model (VOS, Virtual Object System):
The type systemObject-oriented principles (type, inheritance)
Too much for some (non-O-O languages)Too little for some: multiple inheritance (Eiffel)Difficult features: overloading
Must observe the Common Language Specification (CLS)
![Page 27: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/27.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
27
Chair of Software Engineering
Common Language Specification
Set of rules – more restrictive than the .NET object model – to determine compatibility.
Part of the ECMA standard
Three levels:Producer (“framework”)ConsumerExtender
![Page 28: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/28.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
28
Chair of Software Engineering
CLS rules example
(Overloading) “Methods and events that have the same name must be distinguished by at least one argument type.”
Producer: Must mark any offending methods/events as non-CLS-compliant.Consumer: Need not accept types that violate these rules, except if marked non-compliant.Extender: Need not provide syntax for defining types that violate this rule.
![Page 29: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/29.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
29
Chair of Software Engineering
The .NET type system
ReferenceValue
Built-in
Floatingtype
Typedref
Integertype
User-defined
Enums
Pointer
ManagedUnmanaged
Function
Interface
Type
Class
Structure-equivalent
Boxed enum
Array
Delegate
Name-equivalent
Boxed value type
![Page 30: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/30.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
30
Chair of Software Engineering
Value vs. reference types
Value types denote values (simple value or objects).
Reference types denote location of values.
![Page 31: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/31.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
31
Chair of Software Engineering
Simple value vs. object
A simple value cannotby itself identify its type.
Ex: int32, float 32
An object carries its own type description. Type info
Fields342
"A string"
342
An object
A simple value
![Page 32: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/32.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
32
Chair of Software Engineering
Value vs. reference types
Every value type has a corresponding reference type: its “boxed” version.
Some reference types have a corresponding value type: an “unboxed” version.
Limitation: Inheritance and interfaces apply only to reference types.
Type info342
Boxed
342Unboxed
![Page 33: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/33.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
33
Chair of Software Engineering
Built-in types
boolcharint8, int16, int32, int64unsigned int8, unsigned int16, unsigned int32, unsigned int64native int, native unsigned intfloat32, float64System.object, System.stringtypedref
*not in CLS
![Page 34: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/34.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
34
Chair of Software Engineering
Agenda for today
What is .NET?C# basicsEiffel for .NET
![Page 35: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/35.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
35
Chair of Software Engineering
The C# language
“Simplified version of C++”Benefits from the Java experienceThe native language of the .NET framework
![Page 36: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/36.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
36
Chair of Software Engineering
C# and Java
Object-oriented: classes, objects, dynamic allocation, inheritance, polymorphism, dynamic binding…Type-safe by default (no C++ casts)Support for overloadingSupport for garbage collectionNo multiple inheritance from classesNo genericity
![Page 37: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/37.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
37
Chair of Software Engineering
C# vs. Java
Coherent type systemClose integration with other languagesCompiler directives Every piece of software is in a classVariables initialized automaticallyEvent-delegate modelPropertiesException handling
![Page 38: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/38.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
38
Chair of Software Engineering
“Hello World!” in C#
using System;
public class Hello {static void Main() {
Console.WriteLine( “Hello World!” );}
}
Compiler command line: csc Hello.cs
![Page 39: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/39.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
39
Chair of Software Engineering
Classes
A class consists of members:FieldsMethodsPropertiesEvents
![Page 40: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/40.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
40
Chair of Software Engineering
Methods
Algorithms associated with the classWork on an instance (unless static).Instance calls or virtual callsA virtual method may be overridden in a descendant class.A virtual method may be marked final.
![Page 41: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/41.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
41
Chair of Software Engineering
Information hiding (1/2)
Access every object through the officialoperations of its interface.Possible member status:
PublicPrivateFamily: descendant types only AssemblyFamily and assemblyFamily or assembly
![Page 42: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/42.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
42
Chair of Software Engineering
Information hiding (2/2)
!Direct field modification (e.g. C++, Java):heater.temperature := 19
Proper O-O technique:set_temperature (t: INTEGER) is
doif not in_range (t) then
-- Error …else
temperature := tnotify_observers
endend
![Page 43: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/43.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
43
Chair of Software Engineering
The .NET solution: Properties
public class Heater {
private int TemperatureInternal;
public int Temperature {
get {return TemperatureInternal;}
set {if (! InRange (value)) {
throw new ArgumentException(“Temperature out of range");
}TemperatureInternal = value;NotifyObservers;
}}
![Page 44: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/44.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
44
Chair of Software Engineering
Events and Delegates
Purpose: Event-driven programming
A delegate is an object representing a method of a particular class (like function pointer, but typed).
Basic methods on delegates: InvokeBeginInvokeEndInvoke
Associate one or more delegates with each event.
No way to specify “closed” arguments
![Page 45: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/45.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
45
Chair of Software Engineering
Setting an event handler
Button ClickMe = new Button ();ClickMe.Text = "Click me!";
ClickMe.Location = new System.Drawing.Point (200, 30);ClickMe.Size = new System.Drawing.Size (30, 10);
EventHandler MyHandler = new EventHandler (this.ButtonClicked);ClickMe.Click += MyHandler;
void ButtonClicked (Object sender, EventArgs args) {…}
![Page 46: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/46.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
46
Chair of Software Engineering
The event definition
public class Button{
public event EventHandler Click;
protected void OnClick (EventArgs e) {if (Click != null)
Click (this, e);}
}
![Page 47: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/47.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
47
Chair of Software Engineering
Exception handling
Similar to the Java model:try {
// code that may cause an exception}catch (ExceptionType exc) {
if CanFix() {FixIt();
}else throw new Exception();
}catch (OtherExceptionType exc) {…}
![Page 48: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/48.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
48
Chair of Software Engineering
Agenda for today
What is .NET?C# basicsEiffel for .NET
![Page 49: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/49.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
49
Chair of Software Engineering
Eiffel for .NET
Full implementation of Eiffel on .NET:Design by ContractSeamlessness of software developmentMultiple inheritanceGenericity…
Large set of libraries:Eiffel libraries + .NET libraries
Directly available in EiffelStudio
Integrated into Visual Studio.NET: Eiffel ENViSioN!™Smart editorProject clusters browsing…
![Page 50: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/50.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
50
Chair of Software Engineering
Design by Contract on .NET
Like Eiffel, Eiffel for .NET directly enforces Design by Contract, which addresses:
CorrectnessDocumentationDebugging and testingInheritance controlManagement
Eiffel for .NET is the sole language on .NET to support contracts.
![Page 51: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/51.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
51
Chair of Software Engineering
Seamlessness of software development
Like Eiffel, Eiffel for .NET covers the entire software lifecycle.
EiffelStudio provides complete reversibilitybetween class text and diagrams.
![Page 52: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/52.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
52
Chair of Software Engineering
ISE EiffelStudio
![Page 53: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/53.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
53
Chair of Software Engineering
Multiple inheritance and genericity…
… Or how to map non-CLS compliantmechanisms on .NET while preserving languageinteroperability?
![Page 54: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/54.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
54
Chair of Software Engineering
Multiple inheritance on .NET (1/2)
How Eiffel for .NET does it: Taking full advantage of interfaces and namespaces.
A
Impl.A
B
Impl.B
C
Impl.C
Shadowing classes with interfaces.
![Page 55: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/55.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
55
Chair of Software Engineering
Multiple inheritance on .NET (2/2)
What about class instantiation?
A
Impl.A
B
Impl.B
C
Impl.C
Create.A
Create.C
Create.B
![Page 56: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/56.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
56
Chair of Software Engineering
Genericity and covariance on .NET
Eiffel for .NET:Supports genericity.Implements a safe variant of covariance (with type checking) detecting catcalls at run-time.
![Page 57: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/57.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
57
Chair of Software Engineering
“Hello World!” with Eiffel for .NET
class
HELLO_WORLD
create
make
feature {NONE} -- Initialization
make is-- Print Hello_world_message.
doio.put_string (Hello_world_message)
end
feature -- Constant
Hello_world_message: STRING is “Hello World!”-- Hello World! message
end
![Page 58: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/58.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
58
Chair of Software Engineering
Full interoperability on .NET (1/4)
With C#:
public class HelloWorld1{
public static void Main() {HelloWorld sample;sample = Create.HelloWorld.Make();
}}
![Page 59: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/59.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
59
Chair of Software Engineering
Full interoperability on .NET (2/4)
With VB.NET:
Public Class HelloWorld1
Public Sub Main ()Dim sample as HelloWorldsample = Create.HelloWorld.Make()
End Sub
End Class
![Page 60: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/60.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
60
Chair of Software Engineering
Full interoperability on .NET (3/4)
With C#:
using System;
public class HelloWorld2: Impl.HelloWorld{
public static void Main() {HelloWorld sample;sample = new Impl.HelloWorld();Console.WriteLine (
sample.HelloWorldMessage());}
}
![Page 61: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/61.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
61
Chair of Software Engineering
Full interoperability on .NET (4/4)
With VB.NET:
Imports System
Public Class HelloWorld2Inherits Impl.HelloWorld
Public Shared Sub Main() Dim h2 as HelloWorld2h2 = new HelloWorld2()Console.WriteLine (h2.HelloWorldMessage())
End SubEnd Class
![Page 62: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/62.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
62
Chair of Software Engineering
Eiffel for .NET in Visual Studio.NET
EiffelStudio and Visual Studio.NET, two complementary development environments:
EiffelStudio for possibly multi-platformdevelopment in Eiffel only.
Visual Studio.NET for multi-languagedevelopment.
![Page 63: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/63.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
63
Chair of Software Engineering
Windows Forms and Eiffel for .NET
… Or how to take advantage from .NET libraries from an Eiffel for .NET project.
Demo
![Page 64: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/64.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
64
Chair of Software Engineering
Web services with Eiffel for .NET
It is possible to write ASP.NET pages directly in Eiffel for .NET.
<%@ Page Language = “Eiffel” %>
The registration page demo with Eiffel for .NET
![Page 65: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/65.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
65
Chair of Software Engineering
References
Karine Arnout: Introduction to Eiffel for .NET. CoDe Magazine, Sept/Oct 2002.
Bertrand Meyer: The .NET Training Course. Prentice Hall, 2001.
Bertrand Meyer, Raphaël Simon, Emmanuel Stapf: Instant .NET. Prentice Hall, 2002 (in preparation).
Microsoft: .NET Reference documentation. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/cpref_start.asp.
Raphaël Simon, Emmanuel Stapf, Bertrand Meyer: Full Eiffel on .NET. MSDN, 2002.
![Page 66: Chair of Software Engineering - se.inf.ethz.chse.inf.ethz.ch/old/teaching/ws2004/0239/slides/tc_26_dotnet.pdf · Web development. Trusted Components: Reuse, Contracts and Patterns](https://reader034.vdocuments.net/reader034/viewer/2022042322/5f0ca5277e708231d4366f0e/html5/thumbnails/66.jpg)
Trusted Components: Reuse, Contracts and Patterns - Lecture 26
66
Chair of Software Engineering
End of lecture 26