SlideShare a Scribd company logo
1 of 8
Download to read offline
Fluent API design


Joar Øyen
@joaroyen
www.joaroyen.com
Innpakking av kompleks tredjeparts bibliotek
           Slike biblioteker har typisk funksjonalitet du ikke trenger
Hvorfor?
           Veileder brukeren (dvs. utvikleren) hva som er semantisk
           gyldig i henhold til forretningsregler, og ikke bare hva som
           syntaktisk er mulig

           Lesbarhet
Alternativ til
       über-klasse som parameter
Når?   lang liste av overloads
       deklarativ konfigurasjon

       Biblioteker som i stor grad skal benyttes av andre

       For komplekse API som brukes sjelden (dvs. at
       kompleksiteten brukes sjelden)
Mikroskopisk domenespesifikt språk

Hvordan?   Builder pattern

           Det mest vanlige skal alltid resultere i enklest (minst) kode

           Ordenes rekkefølge er viktig

           Ett eller flere startpunkt
           Interface med tilhørende implementasjon
           Statisk wrapper
           Extension metoder
Log.Message(
                "Ingen tilgang til {0}. Verifiser at serveren er tilgjengelig.",
                FilePath);
Eksempler
            Log.Message(
                42,
                "Ingen tilgang til {0}. Verifiser at serveren er tilgjengelig.",
                FilePath);

            Log.Message(Resources.NoAccessToResource, FilePath);

            Log.Exception(new TimeoutException("Test"), "Message");

            Log.UnhandledException(new TimeoutException("Message"));

            Log.Warning.Exception(new TimeoutException("Message"));

            Log.Information.To("Debug").Message("Message");

            Debug.Message("Message");
Fra ett metodekall til 5 interfaces og 11 klasser
Hva har vi   Fra «über klasse» og «overloads from hell» til «train wreck»
oppnådd?
             Syntaktisk sukker
                         Log                                             Message

                                           Error
                                                                        Exception

                                         Warning               To


                                        Information

                                                                    UnhandledException


             Det mest vanlige blir veldig enkelt
             Veiviser for utviklere for avanserte scenarioer
             Lesbar og testbar kode
Vær konsistent
Generelt   Følg Microsofts retningslinjer
råd        Design Guidelines for Developing Class Libraries
           http://msdn.microsoft.com/en-us/library/vstudio/ms229042(v=vs.100).aspx
           Framework Design Guidelines
           http://books.google.no/books/about/Framework_Design_Guidelines.html?id
           =39d1wZ598ecC&redir_esc=y
Antall kodelinjer er ikke indikatoren på hvor kompleks
          løsningen er - det er leserens forståelse av koden som
Budskap   indikerer hvor elegant løsningen er implementert

          Når du lager kode som skal brukes av andre - invester i
          brukervennlighet slik du ville ha gjort for en bruker som
          sitter i brukergrensesnittet

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Fluent api design

  • 1. Fluent API design Joar Øyen @joaroyen www.joaroyen.com
  • 2. Innpakking av kompleks tredjeparts bibliotek Slike biblioteker har typisk funksjonalitet du ikke trenger Hvorfor? Veileder brukeren (dvs. utvikleren) hva som er semantisk gyldig i henhold til forretningsregler, og ikke bare hva som syntaktisk er mulig Lesbarhet
  • 3. Alternativ til über-klasse som parameter Når? lang liste av overloads deklarativ konfigurasjon Biblioteker som i stor grad skal benyttes av andre For komplekse API som brukes sjelden (dvs. at kompleksiteten brukes sjelden)
  • 4. Mikroskopisk domenespesifikt språk Hvordan? Builder pattern Det mest vanlige skal alltid resultere i enklest (minst) kode Ordenes rekkefølge er viktig Ett eller flere startpunkt Interface med tilhørende implementasjon Statisk wrapper Extension metoder
  • 5. Log.Message( "Ingen tilgang til {0}. Verifiser at serveren er tilgjengelig.", FilePath); Eksempler Log.Message( 42, "Ingen tilgang til {0}. Verifiser at serveren er tilgjengelig.", FilePath); Log.Message(Resources.NoAccessToResource, FilePath); Log.Exception(new TimeoutException("Test"), "Message"); Log.UnhandledException(new TimeoutException("Message")); Log.Warning.Exception(new TimeoutException("Message")); Log.Information.To("Debug").Message("Message"); Debug.Message("Message");
  • 6. Fra ett metodekall til 5 interfaces og 11 klasser Hva har vi Fra «über klasse» og «overloads from hell» til «train wreck» oppnådd? Syntaktisk sukker Log Message Error Exception Warning To Information UnhandledException Det mest vanlige blir veldig enkelt Veiviser for utviklere for avanserte scenarioer Lesbar og testbar kode
  • 7. Vær konsistent Generelt Følg Microsofts retningslinjer råd Design Guidelines for Developing Class Libraries http://msdn.microsoft.com/en-us/library/vstudio/ms229042(v=vs.100).aspx Framework Design Guidelines http://books.google.no/books/about/Framework_Design_Guidelines.html?id =39d1wZ598ecC&redir_esc=y
  • 8. Antall kodelinjer er ikke indikatoren på hvor kompleks løsningen er - det er leserens forståelse av koden som Budskap indikerer hvor elegant løsningen er implementert Når du lager kode som skal brukes av andre - invester i brukervennlighet slik du ville ha gjort for en bruker som sitter i brukergrensesnittet