1 / 15

Quack, waddle

Quack, waddle. Barry Dorrans barryd@idunno.org. Duck Typing. If it walks like a duck and quacks like a duck, it’s a duck. And this means what?. A concentration on the aspects of the object, not the underlying type. And this means what?.

agatha
Download Presentation

Quack, waddle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Quack, waddle Barry Dorrans barryd@idunno.org

  2. Duck Typing If it walks like a duck and quacks like a duck, it’s a duck.

  3. And this means what? A concentration on the aspects of the object, not the underlying type.

  4. And this means what? Who cares what the type is; if it quacks and walks then we may treat it as a duck.

  5. From Python; EAFP Easier to Ask Forgivenessthan Permission. No typeof(), isinstance(). Central to Ruby’s approach.

  6. Object Substitution Substitution can occur if an object supports the methods and properties of the expected type in use in the accepting method.

  7. Type Safety is the one true way Static types can slow productivity. .NET already has duck typing …

  8. Liskoff Substitution Principle Subclasses can substitute base class, based on type. Duck typing substitutes on ability.

  9. .NET foreach() quacks Provide a public method GetEnumerator that takes no parameters and returns a type that has two members: a method MoveNext that takes no parameters and return a Boolean, and a property Current with a getter that returns an Object.

  10. So it’s C# 3.0 var then? var declarations are decided at compile time. var is type safe.

  11. And what use is this? Very loose coupling. Type checking breaks encapsulation. Substituting Sealed classes. Testing & mock objects. Plugin versioning architectures.

  12. Killer Beak Duck typing is not performant.

  13. Code Time

  14. Library Availability www.deftflux.net/blog/page/Duck-Typing-Project.aspx Depends on http://www.codeplex.com/NGenerics

  15. And yes;duck quacks do echo www.acoustics.salford.ac.uk/acoustics_info/duck/

More Related