Atitit. The nature of the delegate c#.net Java PHP comparison

Source: Internet
Author: User
Tags call back

The difference between Atitit.class and type , the abstract level class, the nature of the Delegate,interface delegate

1. The delegate is a finer-grained interface 1

2. Delegation Mode 1

3. Delegation in Java 1

4. the difference between class and type 2

1. The delegate is a finer-grained interface

Interfaces (interface) are class-oriented, whereas delegates (delegate) are method-oriented and property. Interfaces must be applied on the class, and delegates are applied on methods and properties.

When the parameter of a method is a delegate type, because the presence of an anonymous delegate makes the invocation easier-this time the method is a property and is assigned directly to the parameter.

The delegation narrows the influence of the "external constraint/external contract" to a single method, rather than affecting the entire class like an interface.

A delegate is allowed to inherit, which means that the delegate has polymorphic functions, such as using a delegate for a policy pattern.

In MSDN, class, Delegate,interface, and is listed as the three major types in. NET (type), but delegate is finer than interface granularity. Microsoft said in the relevant document, can use delegate to complete, can use interface instead.

The argument in Java is a functional interface (JDK8 only supports delegation)

Author :: Old Wow's paw attilax ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

2. Delegate mode

is a basic technique in software design patterns. In delegate mode, there are two objects involved in processing the same request, and the object that accepts the request delegates the request to another object for processing. The delegate mode is a basic technique, and many other patterns, such as state mode, policy mode, and visitor pattern, are in essence a delegate mode in more special situations. The delegate mode allows us to use aggregations instead of inheritance, which also allows us to simulate mixin.

3. Delegates in Java


"Delegate" is a language-level feature in C #, and there is no direct correspondence in the Java language, but we can implement a delegate through a dynamic proxy! The code is as follows:.

Delegate is just one way of saying that in Java, the same argument is call back

JDK8 already has the implementation of the delegate: Functional interface "is the delegate of C # (delegate)

4. Classwith thetypethe Difference

You can understand class as a subset of type

Type is a special class that describes the attributes of the type itself, such as the name, namespace, assembly, and properties that are owned. Method. Properties, etc., gets the owning Type:aObject.GetType () of a class instance, gets the Type:typeof keyword that belongs to a type .

Atitit. The nature of the delegate c#.net Java PHP comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.