Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand - - PowerPoint PPT Presentation

trusted components
SMART_READER_LITE
LIVE PREVIEW

Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand - - PowerPoint PPT Presentation

1 Last update: 2 November 2004 Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand Meyer Dr. Karine Arnout Chair of Softw are Engineering Trusted Components: Reuse, Contracts and Patterns - Lecture 26 2 Lecture 26:


slide-1
SLIDE 1

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

1

Chair of Softw are Engineering

Last update: 2 November 2004

Trusted Components

Reuse, Contracts and Patterns

  • Prof. Dr. Bertrand Meyer
  • Dr. Karine Arnout
slide-2
SLIDE 2

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

2

Chair of Softw are Engineering

Lecture 26: Component model: The .NET example

slide-3
SLIDE 3

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

3

Chair of Softw are Engineering

Agenda for today

  • What is .NET?
  • C# basics
  • Eiffel for .NET
slide-4
SLIDE 4

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

4

Chair of Softw are Engineering

What .NET is not?

  • NOT a programming language:
  • “C# is not .NET and .NET is not C# ”
  • NOT an operating system (yet).
slide-5
SLIDE 5

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

5

Chair of Softw are Engineering

What .NET is…

An open-language platform for enterprise and Web development.

slide-6
SLIDE 6

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

6

Chair of Softw are Engineering

The scope of .NET

.NET addresses almost everyone: The general public New user-friendly services Businesses Help improve “B2B” relationships. Developers Security Programming-language interoperability Component-based development Versioning Memory management

slide-7
SLIDE 7

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

7

Chair of Softw are Engineering

The .NET architecture

UDDI, WSDL, Passport Web services XML & SOAP Open 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.Net Development environment Common Language Runtime (CLR) Compilation, execution… Hardware, Operating system, database system Underlying platform

slide-8
SLIDE 8

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

8

Chair of Softw are 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.

slide-9
SLIDE 9

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

9

Chair of Softw are Engineering

The .NET execution model

slide-10
SLIDE 10

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

10

Chair of Softw are 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+ +

slide-11
SLIDE 11

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

11

Chair of Softw are Engineering

The assembly

Compiled form of a set of classes The .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.

slide-12
SLIDE 12

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

12

Chair of Softw are Engineering

The Global Assembly Cache

slide-13
SLIDE 13

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

13

Chair of Softw are Engineering

.NET core assembly (mscorlib.dll)

slide-14
SLIDE 14

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

14

Chair of Softw are Engineering

.NET libraries (1/ 2)

Nam espace W hat 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

slide-15
SLIDE 15

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

15

Chair of Softw are Engineering

.NET libraries (2/ 2)

Nam espace W hat 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.

slide-16
SLIDE 16

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

16

Chair of Softw are Engineering

Towards new services…

A (demo) conference registration page

slide-17
SLIDE 17

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

17

Chair of Softw are Engineering

Successful registration

slide-18
SLIDE 18

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

18

Chair of Softw are Engineering

Passing erroneous data

slide-19
SLIDE 19

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

19

Chair of Softw are Engineering

About this demo…

Some of what this demo illustrates: ASP.NET (Active Server Pages .NET) Server-side mechanisms, server controls Debugging Web applications like traditional ones Our first C# example… Multi-language development (C# , Eiffel for .NET)

slide-20
SLIDE 20

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

20

Chair of Softw are Engineering

The ASP.NET source

slide-21
SLIDE 21

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

21

Chair of Softw are Engineering

Multi-language support

C++ C# Eiffel Framework

...

Windows

slide-22
SLIDE 22

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

22

Chair of Softw are Engineering

Languages on .NET (1/ 3)

“Microsoft languages” Visual Basic.Net C# Managed C+ + Jscript Commercial languages (see next) Research languages (see next)

slide-23
SLIDE 23

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

23

Chair of Softw are 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)

slide-24
SLIDE 24

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

24

Chair of Softw are Engineering

Languages on .NET (3/ 3)

Research languages: CAML (INRIA) Mercury (Melbourne Uni.) Scheme Oberon (ETH, Zürich) Component Pascal (QUT) Haskell (Universities, Microsoft Research UK)

slide-25
SLIDE 25

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

25

Chair of Softw are Engineering

Full interoperability

Cross-language… Inheritance

Classes can inherit from each other, regardless of language of origin. No need for wrappers No IDL

Debugging sessions In Visual Studio.Net Exceptions

slide-26
SLIDE 26

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

26

Chair of Softw are Engineering

Full interoperability: the price to pay…

Must conform to the .NET object model (VOS, Virtual Object System): The type system Object-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)

slide-27
SLIDE 27

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

27

Chair of Softw are 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”) Consumer Extender

slide-28
SLIDE 28

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

28

Chair of Softw are 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.

slide-29
SLIDE 29

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

29

Chair of Softw are Engineering

The .NET type system

Reference Value Built-in Floating type Typed ref Integer type User- defined Enums Pointer Managed Unmanaged Function Interface Type Class Structure- equivalent Boxed enum Array Delegate Name- equivalent Boxed value type

slide-30
SLIDE 30

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

30

Chair of Softw are Engineering

Value vs. reference types

Value types denote values (simple value or

  • bjects).

Reference types denote location of values.

slide-31
SLIDE 31

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

31

Chair of Softw are Engineering

Simple value vs. object

A simple value cannot by itself identify its type. Ex: int32, float 32 An object carries its

  • wn type description.

Type info Fields 342 "A string" 342

An object

A simple value

slide-32
SLIDE 32

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

32

Chair of Softw are 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

  • nly

to reference types.

Type info 342

Boxed

342

Unboxed

slide-33
SLIDE 33

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

33

Chair of Softw are Engineering

Built-in types

bool char int8, int16, int32, int64 unsigned int8, unsigned int16, unsigned int32, unsigned int64 native int, native unsigned int float32, float64 System.object, System.string typedref

* not in CLS

slide-34
SLIDE 34

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

34

Chair of Softw are Engineering

Agenda for today

  • What is .NET?
  • C# basics
  • Eiffel for .NET
slide-35
SLIDE 35

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

35

Chair of Softw are Engineering

The C# language

“Simplified version of C+ + ” Benefits from the Java experience The native language of the .NET framework

slide-36
SLIDE 36

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

36

Chair of Softw are Engineering

C# and Java

Object-oriented: classes, objects, dynamic allocation, inheritance, polymorphism, dynamic binding… Type-safe by default (no C+ + casts) Support for overloading Support for garbage collection No multiple inheritance from classes No genericity

slide-37
SLIDE 37

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

37

Chair of Softw are Engineering

C# vs. Java

Coherent type system Close integration with other languages Compiler directives Every piece of software is in a class Variables initialized automatically Event-delegate model Properties Exception handling

slide-38
SLIDE 38

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

38

Chair of Softw are Engineering

“Hello World!” in C#

using System; public class Hello { static void Main() { Console.WriteLine( “Hello World!” ); } } Compiler command line: csc Hello.cs

slide-39
SLIDE 39

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

39

Chair of Softw are Engineering

Classes

A class consists of members: Fields Methods Properties Events

slide-40
SLIDE 40

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

40

Chair of Softw are Engineering

Methods

Algorithms associated with the class Work on an instance (unless static). Instance calls or virtual calls A virtual method may be overridden in a descendant class. A virtual method may be marked final.

slide-41
SLIDE 41

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

41

Chair of Softw are Engineering

Information hiding (1/ 2)

Access every object through the official

  • perations of its interface.

Possible member status: Public Private Family: descendant types only Assembly Family and assembly Family or assembly

slide-42
SLIDE 42

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

42

Chair of Softw are Engineering

Information hiding (2/ 2)

!

Direct field modification (e.g. C+ + , Java):

heater.temperature : = 19

Proper O-O technique:

set_temperature (t: INTEGER) is do if not in_range (t) then

  • - Error …

else temperature : = t notify_observers end end

slide-43
SLIDE 43

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

43

Chair of Softw are 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; } }

slide-44
SLIDE 44

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

44

Chair of Softw are 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: Invoke BeginInvoke EndInvoke Associate one or more delegates with each event. No way to specify “closed” arguments

slide-45
SLIDE 45

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

45

Chair of Softw are 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) { … }

slide-46
SLIDE 46

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

46

Chair of Softw are Engineering

The event definition

public class Button { public event EventHandler Click; protected void OnClick (EventArgs e) { if (Click != null) Click (this, e); } }

slide-47
SLIDE 47

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

47

Chair of Softw are 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) { … }

slide-48
SLIDE 48

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

48

Chair of Softw are Engineering

Agenda for today

  • What is .NET?
  • C# basics
  • Eiffel for .NET
slide-49
SLIDE 49

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

49

Chair of Softw are Engineering

Eiffel for .NET

Full implementation of Eiffel on .NET: Design by Contract Seamlessness of software development Multiple inheritance Genericity… Large set of libraries: Eiffel libraries + .NET libraries Directly available in EiffelStudio Integrated into Visual Studio.NET: Eiffel ENViSioN!™ Smart editor Project clusters browsing…

slide-50
SLIDE 50

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

50

Chair of Softw are Engineering

Design by Contract on .NET

Like Eiffel, Eiffel for .NET directly enforces Design by Contract, which addresses: Correctness Documentation Debugging and testing Inheritance control Management Eiffel for .NET is the sole language on .NET to support contracts.

slide-51
SLIDE 51

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

51

Chair of Softw are Engineering

Seamlessness of software development

Like Eiffel, Eiffel for .NET covers the entire software lifecycle. EiffelStudio provides complete reversibility between class text and diagrams.

slide-52
SLIDE 52

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

52

Chair of Softw are Engineering

ISE EiffelStudio

slide-53
SLIDE 53

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

53

Chair of Softw are Engineering

Multiple inheritance and genericity…

… Or how to map non-CLS compliant mechanisms on .NET while preserving language interoperability?

slide-54
SLIDE 54

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

54

Chair of Softw are 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.

slide-55
SLIDE 55

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

55

Chair of Softw are 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

slide-56
SLIDE 56

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

56

Chair of Softw are 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.

slide-57
SLIDE 57

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

57

Chair of Softw are Engineering

“Hello World!” with Eiffel for .NET

class HELLO_WORLD create make feature { NONE} -- Initialization make is

  • - Print Hello_world_message.

do io.put_string (Hello_world_message) end feature -- Constant Hello_world_message: STRING is “Hello World!”

  • - Hello World! message

end

slide-58
SLIDE 58

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

58

Chair of Softw are Engineering

Full interoperability on .NET (1/ 4)

With C# : public class HelloWorld1 { public static void Main() { HelloWorld sample; sample = Create.HelloWorld.Make(); } }

slide-59
SLIDE 59

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

59

Chair of Softw are Engineering

Full interoperability on .NET (2/ 4)

With VB.NET: Public Class HelloWorld1 Public Sub Main () Dim sample as HelloWorld sample = Create.HelloWorld.Make() End Sub End Class

slide-60
SLIDE 60

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

60

Chair of Softw are 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()); } }

slide-61
SLIDE 61

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

61

Chair of Softw are Engineering

Full interoperability on .NET (4/ 4)

With VB.NET: Imports System Public Class HelloWorld2 Inherits Impl.HelloWorld Public Shared Sub Main() Dim h2 as HelloWorld2 h2 = new HelloWorld2() Console.WriteLine (h2.HelloWorldMessage()) End Sub End Class

slide-62
SLIDE 62

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

62

Chair of Softw are Engineering

Eiffel for .NET in Visual Studio.NET

EiffelStudio and Visual Studio.NET, two complementary development environments: EiffelStudio for possibly multi-platform development in Eiffel only. Visual Studio.NET for multi-language development.

slide-63
SLIDE 63

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

63

Chair of Softw are Engineering

Windows Forms and Eiffel for .NET

… Or how to take advantage from .NET libraries from an Eiffel for .NET project. Dem o

slide-64
SLIDE 64

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

64

Chair of Softw are 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 dem o w ith Eiffel for .NET

slide-65
SLIDE 65

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

65

Chair of Softw are 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?ur l= / library/ en-us/ cpref/ html/ cpref_start.asp.

  • Raphaël Simon, Emmanuel Stapf, Bertrand

Meyer: Full Eiffel on .NET. MSDN, 2002.

slide-66
SLIDE 66

Trusted Components: Reuse, Contracts and Patterns - Lecture 26

66

Chair of Softw are Engineering

End of lecture 26