Microsoft .NET 3. Language Innovations Pan Wuming 2017
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)
1. Three New Languages C# IL F#
2. Evolving from OO Paradigm Solving OO Defects Multi-inheritance Name conflicts Everything is object Members For Abstraction Accessibility for Encapsulation Inheritance And Polymorphism
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
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
Members for Abstraction Fields Properties Events Constructors Methods Nested types Members for Abstraction
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.
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.
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.
3. Towards higher order: Expressiveness Delegate Lambda Expression Generic LINQ Extension method Effective Coding
Lambda Expression
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!";
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
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.
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
Towards Higher Order: Compiling As Services Compiler API Scripting
See you next class Layperson Professional