Glossary: Duck typing

Source: Internet
Author: User

Duck Typing: In computer science,Duck TypingIs a form of dynamic type: the value of a variable implicitly determines the behavior of a variable. This implies that an object can be exchanged with other objects that implement the same interface, regardless of whether the object has an inheritance relationship.Duck TypingYesProgramming LanguageFeatures: smalltalk, Python, Ruby, and ColdFusion.

Duck TypingIs a duck test (DuckTest) A reference -- "if it walks like a duck, it must be called as a duck, then it must be a duck ".

Alex Martelli is considered the inventor of this term by posting information on the comp. Lang. Python newsgroup.

In smalltalk, any object can be exchanged with other objects at runtime. This is the most flexible dynamic type.Duck TypingTry to limit this flexibility to remove possible error sources before running. Smalltalk framework engineers are exploring for true polymorphism, and may introduce errors at runtime. In practice, these errors can be detected through the Sunit test at runtime.

Abstract data types are dynamic interfaces. They exist only in guarantee, paper, and specific interfaces. Smalltalk uses purely dynamic mechanisms to expand guarantee in practice in a changed way. This is as simple as the general "method not found" exception processor in the catch mechanism. But it can call extension languages or environments, such as strongtalk. Exception Handling in parallel with Smalltalk is called in Java and PythonDuck Typing, A single reason for syntax improvement.

The C ++ template implements a staticDuck Typing. For example, an iterator cannot inherit methods from a base class of an iterator.

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.