EXTENSION METHODS. Sander Hoogendoorn, village idiot, Capgemini EXTENSION METHODS Capgemini. All Rights Reserved

Vergelijkbare documenten
General info on using shopping carts with Ingenico epayments

SAMPLE 11 = + 11 = + + Exploring Combinations of Ten + + = = + + = + = = + = = 11. Step Up. Step Ahead

MyDHL+ Van Non-Corporate naar Corporate

ANGSTSTOORNISSEN EN HYPOCHONDRIE: DIAGNOSTIEK EN BEHANDELING (DUTCH EDITION) FROM BOHN STAFLEU VAN LOGHUM

Luister alsjeblieft naar een opname als je de vragen beantwoordt of speel de stukken zelf!

L.Net s88sd16-n aansluitingen en programmering.

Cambridge Assessment International Education Cambridge International General Certificate of Secondary Education. Published

Group work to study a new subject.

L.Net s88sd16-n aansluitingen en programmering.

Settings for the C100BRS4 MAC Address Spoofing with cable Internet.

B1 Woordkennis: Spelling

FOD VOLKSGEZONDHEID, VEILIGHEID VAN DE VOEDSELKETEN EN LEEFMILIEU 25/2/2016. Biocide CLOSED CIRCUIT

Add the standing fingers to get the tens and multiply the closed fingers to get the units.

2010 Integrated reporting

Opgave 2 Geef een korte uitleg van elk van de volgende concepten: De Yield-to-Maturity of a coupon bond.

2019 SUNEXCHANGE USER GUIDE LAST UPDATED

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

Firewall van de Speedtouch 789wl volledig uitschakelen?

Preschool Kindergarten

CTI SUITE TSP DETAILS

ALGORITMIEK: answers exercise class 7

Activant Prophet 21. Prophet 21 Version 12.0 Upgrade Information

The first line of the input contains an integer $t \in \mathbb{n}$. This is followed by $t$ lines of text. This text consists of:

(Big) Data in het sociaal domein

After that, the digits are written after each other: first the row numbers, followed by the column numbers.

z x 1 x 2 x 3 x 4 s 1 s 2 s 3 rij rij rij rij

RECEPTEERKUNDE: PRODUCTZORG EN BEREIDING VAN GENEESMIDDELEN (DUTCH EDITION) FROM BOHN STAFLEU VAN LOGHUM

Het beheren van mijn Tungsten Network Portal account NL 1 Manage my Tungsten Network Portal account EN 14

Read this story in English. My personal story

Find Neighbor Polygons in a Layer

8+ 60 MIN Alleen te spelen in combinatie met het RIFUGIO basisspel. Only to be played in combination with the RIFUGIO basicgame.

Value based healthcare door een quality improvement bril

should(n t) / should(n t) have to zouden moeten / hadden meestergijs.nl

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

Hoe met Windows 8 te verbinden met NDI Remote Office (NDIRO) How to connect With Windows 8 to NDI Remote Office (NDIRO

Bijlage 2: Informatie met betrekking tot goede praktijkvoorbeelden in Londen, het Verenigd Koninkrijk en Queensland

0515 DUTCH (FOREIGN LANGUAGE)

ETS 4.1 Beveiliging & ETS app concept

Puzzle. Fais ft. Afrojack Niveau 3a Song 6 Lesson A Worksheet. a Lees de omschrijvingen. Zet de Engelse woorden in de puzzel.

Interaction Design for the Semantic Web

Esther Lee-Varisco Matt Zhang

It s all about the money Group work

Travel Survey Questionnaires

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

4 JULI 2018 Een eerste kennismaking met gemeentefinanciën en verbonden partijen voor raadsleden - vragen

Een vrouw, een kind en azijn (Dutch Edition)

Screen Design. Deliverable 3 - Visual Design. Pepijn Gieles Docent: Jasper Schelling

Nieuwsbrief NRGD. Editie 11 Newsletter NRGD. Edition 11. pagina 1 van 5.

MyDHL+ Uw accountnummer(s) delen

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE. Toets Inleiding Kansrekening 1 8 februari 2010

Gemeente Ridderkerk Controle jaarrekening Ridderkerk 4 juli 2019 Jesper van Koert Reinier Moet Rein-Aart van Vugt

Disclosure belofte. Ik stel het belang van de patiënt voorop en eerbiedig zijn opvattingen. Doel van de patient staat centraal

Borstkanker: Stichting tegen Kanker (Dutch Edition)

S e v e n P h o t o s f o r O A S E. K r i j n d e K o n i n g

Introductie in flowcharts

Intermax backup exclusion files

(1) De hoofdfunctie van ons gezelschap is het aanbieden van onderwijs. (2) Ons gezelschap is er om kunsteducatie te verbeteren

Vertaling Engels Gedicht / songteksten

Tentamen Objectgeorienteerd Programmeren

GOVERNMENT NOTICE. STAATSKOERANT, 18 AUGUSTUS 2017 No NATIONAL TREASURY. National Treasury/ Nasionale Tesourie NO AUGUST

The Leading Open Source MDA Platform. openmdx 2 Overview. June

Online Resource 1. Title: Implementing the flipped classroom: An exploration of study behaviour and student performance

MyDHL+ Global Mail zending aanmaken

Contents. Introduction Problem Definition The Application Co-operation operation and User friendliness Design Implementation

Duurzaam projectmanagement - De nieuwe realiteit van de projectmanager (Dutch Edition)

Understanding and being understood begins with speaking Dutch

LDAP Server on Yeastar MyPBX & tiptel 31xx/32xx series

Zo werkt het in de apotheek (Basiswerk AG) (Dutch Edition)

Communication about Animal Welfare in Danish Agricultural Education

Leeftijdcheck (NL) Age Check (EN)

Taco Schallenberg Acorel

MyDHL+ ProView activeren in MyDHL+

Een vrouw, een kind en azijn (Dutch Edition)

01/ M-Way. cables

!!!! Wild!Peacock!Omslagdoek!! Vertaling!door!Eerlijke!Wol.!! Het!garen!voor!dit!patroon!is!te!verkrijgen!op! Benodigdheden:!!

Building the next economy met Blockchain en real estate. Lelystad Airport, 2 november 2017 BT Event

Basic operations Implementation options

DALISOFT. 33. Configuring DALI ballasts with the TDS20620V2 DALI Tool. Connect the TDS20620V2. Start DALISOFT

Handleiding Zuludesk Parent

Yes/No (if not you pay an additional EUR 75 fee to be a member in 2020

Chief Secretary Switch with Htek & Yeastar S-series Versie ( )

Process Mining and audit support within financial services. KPMG IT Advisory 18 June 2014

The genesis of the game is unclear. Possibly, dominoes originates from China and the stones were brought here by Marco Polo, but this is uncertain.

Engels op Niveau A2 Workshops Woordkennis 1

Data Handling Ron van Lammeren - Wageningen UR

Comics FILE 4 COMICS BK 2

20 twenty. test. This is a list of things that you can find in a house. Circle the things that you can find in the tree house in the text.

i(i + 1) = xy + y = x + 1, y(1) = 2.

It-servicemanagement op basis van Itil 2011 Editie (Dutch Edition)

Dohmen advocaten: designers en techneuten die advocaat geworden zijn

KPMG PROVADA University 5 juni 2018

My Benefits My Choice applicatie. Registratie & inlogprocedure

Vergaderen in het Engels

Keuzetwijfels in de Emerging Adulthood rondom Studie- en Partnerkeuze. in Relatie tot Depressie

Chapter 4 Understanding Families. In this chapter, you will learn

Example. Dutch language lesson. Dutch & German Language Education Pieter Wielick

A2 Workshops Grammatica Heden

Graphic Design. Keuzevak GD1. Raul Martinez-Orozco / raul@thecombine.nl)

Free time! Better skills. Free time with Brenda and Brian. Worksheet

In the classroom. Who is it? Worksheet

Transcriptie:

Sander Hoogendoorn, village idiot, Capgemini 1

SANDER HOOGENDOORN Capgemini Principal technology officer Global agile thought leader Chief architect Accelerated Delivery Platform (ADP) Other Author books and articles Appreciated speaker at international conferences Microsoft Partner Advisory Council.NET Capping IT Off Blog Column Software Release Magazine Columns SDN Magazine Editorial board Software Release Magazine Editorial board Tijdschrift IT Management (TiTM) Advisory board @Portunity Web www.sanderhoogendoorn.com www.smartusecase.com Twitter: @aahoogendoorn LinkedIn: aahoogendoorn 2

AGENDA Extension methods What are extension methods anyway? Which problem do they solve? How to define an extension method How do they work? How are they implemented? Object oriented principles What is LSP? Do extension methods break LSP? What about OCP? Some usages Extension method levels Extending frameworks Extension method anti-patterns 3

HOW COMPLECITY IS KILLING US 4

THE GARTNER HYPE CURVE 5

PRODUCTIVITY 6

PRODUCTIVITY? 7

THE IT MANAGER IT has become a major roadblock for business agility 8

9

SIMPLICITY? 10

SIMPLICITY? 11

SIMPLICITY? 12

13

Extension methods? 14

WHAT ARE ANYWAY? An often overlooked language feature 15

WHAT ARE ANYWAY? When designing LINQ Implement standard query operators for LINQ Add functionality to IEnumerable and IEnumerable<T> types But without touching the original types! Enter extension methods Any type implementing these will now have OrderBy, GroupBy etc. 16

WHAT ARE ANYWAY? 17

WTF? 18

WHAT PROBLEM DO THEY SOLVE? 19

WHAT S THE PROBLEM ANYWAY? Problem You need to extend an existing type and add functionality to it Options 1. Implement the functionality on the type itself e.g. in a partial class 2. Inherit from the type and add the functionality there override and new? 3. Apply aggregation instead of inheritance 4. Create a (static) helper class and add the functionality there 5. Create the functionality in extension methods 20

OVERRIDING USING NEW KEYWORD Demo 21

USING INHERITANCE Demo 22

USING UTILITY Demo 23

HOW TO DEFINE AN EXTENSION METHOD 24

EXTENSIONS: BEFORE AND AFTER 25

. WTF? Extension methods Enable you to "add" methods to existing types, without derivation Call as if they are methods on the extended type Full IntelliSense support For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type 26

DEFINING AN EXTENSION METHOD Rules for defining extension method Defined in a non-generic non-nested static class Method is static First parameter preceded by the instance parameter this No other parameters (ref, out, etc ) are allowed with modifier this The instance parameter cannot be a pointer Must be public, internal or private In a namespace which is in scope 27

MY FIRST EXTENSION METHOD Demo string.isemail 28

SO HOW ARE IMPLEMENTED? Some MSIL 29

SO HOW ARE IMPLEMENTED? 30

SO HOW ARE IMPLEMENTED? 31

LSP AND OCP Facts of life? 32

LISKOV S SUBSTITUTION PRINCIPLE If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behaviour of P is unchanged when o1 is substituted for o2 then S is a subtype of T. 33

LSP AND OCP Liskov Substitution Principle (LSP) If S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program. Barbara Liskov 1994. Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T. Open Closed Principle (OCP) Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. Betrand Meyer, 1988. 34

BREAKING LSP TWICE Demo 35

LSP AND OCP How do LSP and OCP relate to extension methods? Defined as a static member on a non-generic, static class Not defined on extended class itself Check your MSIL for consequences Thus Extension methods can only get to public properties of extended class And Extension method can not reach extended class internals Concluding Extension methods do not break LSP Extension methods do not break OCP So nice implementation! 36

EXTENSTION METHOD INVOCATION Resolving the order of precedence 37

(EXTENSION) METHOD INVOCATION First try regular method invocation expr.identifier() expr.identifier(args) expr.identifier<typeargs>() expr.identifier<typeargs(args) Only if none resolves find eligble extension methods C.identifier(expr) C.identifier(expr, args) C.identifier<typeargs>(expr) C.identifier<typeargs>(expr, args) Eligble if implicit identity, reference or boxing conversion exists from expr to first parameter of identifier 38

EXTENSION METHOD INVOCATION Demo 39

LEVELS OF 40

TYPES OF Level one Rewriting static framework methods as instance extension methods Format(this string s) Level two Creating new extension methods to solve common problems IsNullOrEmpty(this string s) Level three Using extension methods to embed business and validation logic IsEmail(this string s) Rather use value objects 41

TYPES OF Level four Method chaining Fluent interfaces 5.Sqrt().Power(3) Level five Extending framework functionality DomainObject HtmlHelper Replacing framework functionality Splitting basic from specialized scenarios 42

SIMPLE METHOD CHAINING Demo 43

Extending frameworks 44

EXTENDING EXISTING FRAMEWORKS - ADF 45

EXTENDING EXISTING FRAMEWORKS - ADF 46

EXTENDING EXISTING FRAMEWORKS - ADF 47

EXTENDING EXISTING FRAMEWORKS - CSLA 48

EXTENDING AND REPLACING 49

EXTENDING HTMLHELPER Demo ASP. NET MVC Descriptor pattern 50

EXTENSION METHOD ANTI-PATTERNS Do s and don ts 51

EXTENSION METHOD ANTI-PATTERNS 52

EXTENSION METHOD ANTI-PATTERNS 53

EXTENSION METHOD ANTI-PATTERNS 54

ANTI-PATTERNS 55

SENDING EMAIL? Demo 56

TAKEAWAYS 57

TAKEAWAYS Extension methos In general, you will call extension methods far more than implement your own Don t forget to include the namespace Implement them sparsely Be careful with additional dependencies!! Use extension methods to extend frameworks that do not allow you to extend their types Don t mistake extension methods for value objects, just because they have the same underlying base type Mind your namespaces! 58

WWW.SMARTUSECASE.COM 59

REFERENCES AND QUESTIONS sander.hoogendoorn@capgemini.com www.accelerateddeliveryplatform.com www.smartusecase.com www.sanderhoogendoorn.com sander.hoogendoorn@capgemini.com aahoogendoorn@gmail.com LinkedIn: aahoogendoorn Twitter: @aahoogendoorn 60