Download presentation
Presentation is loading. Please wait.
Published byAusten Morgan Modified over 6 years ago
1
Microsoft .NET 3. Language Innovations Pan Wuming 2017
2
Topics Three New Languages Evolving From OO Paradigm
Towards Higher Order: Expressiveness Towards Higher Order: Contract Enabled Towards Higher Order: Enhanced Dynamics Towards Higher Order: Compiling As Services Three new languages: C#, IL and F# Evolving from OO Paradigm Everything is object Members for Abstraction Accessibility for Encapsulation Inheritance and Polymorphism Solving name confliction and multi-inheritance Towards higher order: Expressiveness Delegate Lambda Expression Generic Attribute LINQ Compiler API Effective coding References: Common Type System(MSDN) .NET Framework Class Library Overview (MSDN) Inheritance (C# Programming Guide) (MSDN) Polymorphism (C# Programming Guide) (MSDN)
3
1. Three New Languages C# IL F#
4
2. Evolving from OO Paradigm
Solving OO Defects Multi-inheritance Name conflicts Everything is object Members For Abstraction Accessibility for Encapsulation Inheritance And Polymorphism
5
Everything is object Classes Structures
Enumerations Interfaces Delegates An assembly is a collection of types Each type is derived from Object Type Five Categories of Types
6
Single Double Boolean Object String Primitive data types Integer
Byte SByte Int16 Int32 Int64 UInt16 UInt32 UInt64 Floating point Single Double Value type = Structure type Or Enumeration type Implicitly inherit from System.ValueType all primitive data types are defined as structures Logical Boolean Other Char Decimal IntPtr UIntPtr Class objects Object String
7
Members for Abstraction
Fields Properties Events Constructors Methods Nested types Members for Abstraction
8
Accessibility for Encapsulation
Traditional OO Accessibility Private Protected Public .NET Accessibility Internal Protected Internal Being Internal, a type or a member is accessible within the boundary of the assembly which contains it.
9
Inheritance and Polymorphism
reuse, extend, and modify the behavior of base classes. Polymorphism At run time, objects of a derived class may be treated as objects of a base. Base classes may define and implement virtual methods, and derived classes can override them.
11
Solving name conflicts and multi-inheritance
A derived class can have only one direct base class. A class or struct can implement multiple interfaces. Explicit implementation is used to resolve name conflicts of two interfaces. However, multi-inheritance without name conflict is a useful means for providing meaningful structure of a program.
13
3. Towards higher order: Expressiveness
Delegate Lambda Expression Generic LINQ Extension method Effective Coding
14
Lambda Expression
15
Effective coding: Examples
Indexers Foreach loop Partial Class Nullable Type Automatic implementation of Property Array Initialization Implicitly Typed Named and Optional Arguments Int? i=5; Instances of the System.Nullable<T> struct public string FirstName { get; set; } = "Jane"; int[] Numbers = { 0, 1, 2, 3, 4 }; var i = 1; var hw = "Hello World!";
16
4. Towards Higher Order: Contract Enabled
Attribute Interact with other program Interact with compiler Example: Serialization Example: Platform Invoke Interact with CLR Example: Caller Information
18
Common Uses for Attributes
Marking methods using the WebMethod attribute in Web services. Describing how to marshal method parameters when interoperating with native code. Describing the COM properties for classes, methods, and interfaces. Calling unmanaged code using the DllImportAttribute class. Describing your assembly in terms of title, version, description, or trademark. Describing which members of a class to serialize for persistence. Describing how to map between class members and XML nodes for XML serialization. Describing the security requirements for methods. Specifying characteristics used to enforce security. Controlling optimizations by the just-in-time (JIT) compiler. Obtaining information about the caller to a method.
19
5. Towards Higher Order: Enhanced Dynamics
Type Class and Reflection Dynamic Language Runtime Dynamic languages can identify the type of an object at run time The ability to use a rapid feedback loop (REPL, or read-evaluate-print loop). Support for both top-down development and more traditional bottom-up development Easier refactoring and code modifications Dynamic languages make excellent scripting languages
20
Towards Higher Order: Compiling As Services
Compiler API Scripting
22
See you next class Layperson Professional
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.