際際滷

際際滷Share a Scribd company logo
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 (20)

How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report by Hubspot
2024 State of Marketing Report  by Hubspot2024 State of Marketing Report  by Hubspot
2024 State of Marketing Report by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
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
ThinkNow
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
marketingartwork
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
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
Neil 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 2024
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
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 Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit 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 management
MindGenius
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report by Hubspot
2024 State of Marketing Report  by Hubspot2024 State of Marketing Report  by Hubspot
2024 State of Marketing Report by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
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
ThinkNow
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
marketingartwork
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
Neil 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 2024
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
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 Intent
Lily Ray
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit 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 management
MindGenius

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