SlideShare a Scribd company logo
What is -duck typing is a style of dynamic typing in which an object's current set of methods and propertiesdetermines the valid semantics, rather than its inheritance from  - a particular class or implementation of a specific interface.DUCK TYPINGPROGRAMMING STYLEPresented byAbdun Nur Tomal
Define -may be phrased as follows:"When I see a bird that walks like a duckand swims like a duck and quacks like a duck, I call that bird a duck.“In duck typing, one is concerned with just those aspects of an object that are used,
rather than with the type of the object itself. DUCK TYPINGPROGRAMMING STYLE
For example :-in a non-duck-typed language,one can create a function that takes an object of type Duck and calls that object's -walk and -quack methods. In a duck-typed language, >the equivalent function would take an object of any type and >call that object's walk and quack methods. >If the object does not have the methods that are called then the function signals a run-time error. >It is this action of any object having the correct walk and quack methods being accepted by the function that evokesthe quotation and hence the name of this form of typing.DUCK TYPINGPROGRAMMING STYLE
example :-Duck typing is aided by habitually not testing for the type of arguments in method and function bodies,
relying on documentation, clear code, and testing to ensure correct use.
pseudo-code for a duck typed language:function calculate(a, b, c) => return (a+b)*c example1 = calculate (1, 2, 3)example2 = calculate ([1, 2, 3], [4, 5, 6], 2) example3 = calculate ('apples ', 'and oranges, ', 3) printto_string example1 printto_string example2 printto_string example3the result of the code would be:9[1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] apples and oranges, apples and oranges, apples and orangesDUCK TYPINGPROGRAMMING STYLE
Thus, duck typing allows polymorphismwithout inheritance.

More Related Content

PPT
Class and Objects in PHP
PPT
Php object orientation and classes
PPT
Class 7 - PHP Object Oriented Programming
PPT
Php Oop
PPTX
Php oop presentation
PPTX
Oop in-php
DOCX
Oops concept in php
Class and Objects in PHP
Php object orientation and classes
Class 7 - PHP Object Oriented Programming
Php Oop
Php oop presentation
Oop in-php
Oops concept in php

What's hot (18)

PPT
Oops in PHP By Nyros Developer
PDF
Intermediate OOP in PHP
PDF
Object Oriented Programming in PHP
PPT
Oops in PHP
PDF
Demystifying oop
PPT
JavaScript In Object Oriented Way
PDF
05 ruby classes
PPTX
Oops in php
PPTX
Classes and objects
PPT
Synapseindia object oriented programming in php
PPT
Ruby For Java Programmers
PDF
A Gentle Introduction To Object Oriented Php
PDF
OOP in PHP
PPT
Oops concepts in php
PPT
ppt9
PPT
name name2 n2.ppt
PPT
ppt18
PPT
name name2 n2
Oops in PHP By Nyros Developer
Intermediate OOP in PHP
Object Oriented Programming in PHP
Oops in PHP
Demystifying oop
JavaScript In Object Oriented Way
05 ruby classes
Oops in php
Classes and objects
Synapseindia object oriented programming in php
Ruby For Java Programmers
A Gentle Introduction To Object Oriented Php
OOP in PHP
Oops concepts in php
ppt9
name name2 n2.ppt
ppt18
name name2 n2
Ad

Similar to Programming Style - Duck Type (20)

PDF
Python lecture 8
PPTX
Polymorphism in Python
PDF
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
PDF
L04 Software Design Examples
PPTX
L04 Software Design 2
PDF
Lecture on Lecture on Python programming OP conceptsPolymorphism.pdf
PPTX
Welcome to Design patterns
PPTX
Polymorphism.pptx
PPTX
Polymorphism
 
PDF
Object-oriented Basics
ODP
Dynamic Python
PDF
Intro To Ruby
PPT
Oops ppt
DOC
Abstract
PPTX
Module 3,4.pptx
PDF
Oop08 6
PDF
Understanding Typing. Understanding Ruby.
PDF
Paulking dlp
PDF
Euclideus_Language
PDF
Object Oriented Program
Python lecture 8
Polymorphism in Python
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
L04 Software Design Examples
L04 Software Design 2
Lecture on Lecture on Python programming OP conceptsPolymorphism.pdf
Welcome to Design patterns
Polymorphism.pptx
Polymorphism
 
Object-oriented Basics
Dynamic Python
Intro To Ruby
Oops ppt
Abstract
Module 3,4.pptx
Oop08 6
Understanding Typing. Understanding Ruby.
Paulking dlp
Euclideus_Language
Object Oriented Program
Ad

More from Sentinel Solutions Ltd (6)

PDF
Aws amazon ec2
PPTX
PPTX
PPTX
PPTX
Programming style - duck type
PPTX
Titanium Studio [Updated - 18/12/2011]
Aws amazon ec2
Programming style - duck type
Titanium Studio [Updated - 18/12/2011]

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Modernizing your data center with Dell and AMD
PPTX
A Presentation on Artificial Intelligence
PDF
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Machine learning based COVID-19 study performance prediction
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Modernizing your data center with Dell and AMD
A Presentation on Artificial Intelligence
Review of recent advances in non-invasive hemoglobin estimation

Programming Style - Duck Type

  • 1. What is -duck typing is a style of dynamic typing in which an object's current set of methods and propertiesdetermines the valid semantics, rather than its inheritance from - a particular class or implementation of a specific interface.DUCK TYPINGPROGRAMMING STYLEPresented byAbdun Nur Tomal
  • 2. Define -may be phrased as follows:"When I see a bird that walks like a duckand swims like a duck and quacks like a duck, I call that bird a duck.“In duck typing, one is concerned with just those aspects of an object that are used,
  • 3. rather than with the type of the object itself. DUCK TYPINGPROGRAMMING STYLE
  • 4. For example :-in a non-duck-typed language,one can create a function that takes an object of type Duck and calls that object's -walk and -quack methods. In a duck-typed language, >the equivalent function would take an object of any type and >call that object's walk and quack methods. >If the object does not have the methods that are called then the function signals a run-time error. >It is this action of any object having the correct walk and quack methods being accepted by the function that evokesthe quotation and hence the name of this form of typing.DUCK TYPINGPROGRAMMING STYLE
  • 5. example :-Duck typing is aided by habitually not testing for the type of arguments in method and function bodies,
  • 6. relying on documentation, clear code, and testing to ensure correct use.
  • 7. pseudo-code for a duck typed language:function calculate(a, b, c) => return (a+b)*c example1 = calculate (1, 2, 3)example2 = calculate ([1, 2, 3], [4, 5, 6], 2) example3 = calculate ('apples ', 'and oranges, ', 3) printto_string example1 printto_string example2 printto_string example3the result of the code would be:9[1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] apples and oranges, apples and oranges, apples and orangesDUCK TYPINGPROGRAMMING STYLE
  • 8. Thus, duck typing allows polymorphismwithout inheritance.
  • 9. The only requirement thatfunction calculate needs in its variables is having the "+" and the "*" methods.
  • 10. The duck test can be seen in the following example:As far as the function in_the_forest is concerned, the Person object is a duck:class Duck: def quack(self):print("Quaaaaaack!") def feathers(self): print("The duck has white and gray feathers.") class Person: def quack(self): print("The person imitates a duck.") def feathers(self): print("The person takes a feather from the ground and shows it.") def name(self): print("John Smith") defin_the_forest(duck): duck.quack() duck.feathers() def game(): donald = Duck() john = Person() in_the_forest(donald) in_the_forest(john) game()DUCK TYPINGPROGRAMMING STYLE
  • 11. This way software can be developed by extending partially working duck typed code.In JavaScriptvar Duck = function () {}; Duck.prototype = { quack: function (){ alert("Quaaaaaack!"); }, feathers: function () { alert("The duck has white and gray feathers."); } }; var Person = function () {}; Person.prototype = { quack: function () { alert("The person imitates a duck."); }, feathers: function () { alert("The person takes a feather from the ground and shows it.");}, name: function () { alert("John Smith"); } }; varin_the_forest = function (duck){ duck.quack(); duck.feathers(); }; var game = function () { vardonald = new Duck(); var john = new Person(); in_the_forest(donald) in_the_forest(john) };game();DUCK TYPINGPROGRAMMING STYLE
  • 12. Resources –Wikipediahttp://en.wikipedia.org/wiki/Duck_typing#Concept_examplesDr. Dobb’shttp://drdobbs.com/cpp/184401971http://drdobbs.com/open-sourceBig Dingushttp://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/Apache Commonshttp://commons.apache.org/proxy/DUCK TYPINGPROGRAMMING STYLE
  • 13. Resources –Wikipediahttp://en.wikipedia.org/wiki/Duck_typing#Concept_examplesDr. Dobb’shttp://drdobbs.com/cpp/184401971http://drdobbs.com/open-sourceBig Dingushttp://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/Apache Commonshttp://commons.apache.org/proxy/DUCK TYPINGPROGRAMMING STYLE