Personal Software Development Practices

  • Don’t fear the code. It’s just code.
  • Never write (or copy) a line of code that you don’t fully understand.
  • Figure out how things really work and why they work they way they do.
  • If you don’t understand something, go deeper. Read the source code for the library you’re using.
  • Use tools to figure out how things work–debugger, unit tests, sample programs.
  • Create a punchlist to guide your work–investigations, things to do, things to test
  • Test the hell out of your code. Be as thorough as possible
  • When you get stuck, go for a 5 minute walk.
  • When you get stuck, describe your stuckness out loud to somebody else.
  • Write down what you’ve learned. Create a FAQ document and answer all the questions.
  • Try to teach someone else what you’ve learned. Create a blog.
  • Leave breadcrumbs for yourself and others–personal notes or comments in the code.

That Conference 2018 – An Extended Explanation of Caching

That Conference 2018, Kalahari Resort, Lake Delton, WI
An Extended Explanation of Caching – Tom Cudd

Day 3, 8 Aug 2018  2:30 PM

Disclaimer: This post contains my own thoughts and notes based on attending That Conference 2018 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of the speakers.

Executive Summary

  • A number of places where you can do caching
  • Various tools for various places
  • Really all about 1) populating, 2) invalidating

Caching examples

  • Network tab in browser, pages from memory or disk cache
  • Content from CDN
  • Special applications – e..g. Varnish
  • WordPress plugin – specify cache settings for blog

Caching is Like Regex

  • If you’re not careful, you’re going to have new problems

Application Architecture

  • “Christmas tree” showing server, cache servers, CDN, load balancers, etc.


  • Caching solves one problem–performance
  • 3-sec rule: user leaves if something takes longer than 3 secs
    • 40% of users leave

Another reason

  • Buy some time
    • e.g. before application crashes
  • Cost-benefit analysis–caching costs vs downtime

Measure First

  • User metrics
  • Load times
  • Site no crashing every 5 minutes
  • S.M.A.R.T. Goals – specific measurable achievable relevant time-bound

How to Not Suck at Caching

  • Caching is additive
    • Can’t just throw caching onto server that’s already overloaded
  • Don’t over-engineer
    • Use the simplest solution that satisfies the requirements
  • Measure, change, test, measure

Caching Doesn’t Help

  • Oversaturation
    • Network hardware
    • Thread death–“virus”, creating multiple threads for each request
  • Thundering herd
    • If you get large number of initial requests, a large number of them go all the way back to server, since it takes a little time to cache the data
  • Lack of information
  • Bad decisions

End Users

Browser Caching

  • Setting request headers–page tells browser to cache a page
  • Requires a hit to operating system
  • Unique naming
    • Rename an assets to force download of long cached object

Set with Web Server

  • E.g. est cache-control for certain pages

External/Edge Services

  • CDN – Content Delivery Network
    • Point your URI to 3rd party server
    • They then pull files, as needed, from your server
  • Most big sites on the web run on CDN
  • Improve page load time
    • Serve request from server that has shortest travel time to client
  • High availability
    • Cached data could still be present even when your origin server hiccups
  • Can maybe buy CDN servies at lower cost than scaling out actual servers

CDN Features

  • Setting TTLs, other configs based on extension
  • Region, language routing
  • Mobile detection
  • WAF/Security
    • Applications can do double duty–firewall + CDN
    • DDOS protection

CDN Providers

  • Cloudflare
  • Incapsula
  • Cloud providers
  • Akamai
  • Fastly


  • Match file extensions
  • Honoe cache control of origin
  • Can have configs for some stuff on your server

Measure and Test

Your Systems

  • Don’t over-engineer–get strange results
  • Spin up different instance if you need different purpose


  • Separate servers
  • Both memory and disk paging

Web/App Layer

  • Baked vs fried
    • Building on demand vs preloading cache
    • Cache gen’d on demand when request hits (fries)
    • Preload cache ahead of time (baked)
  • Disk vs memory


  • Adobe Experience Manager
  • Sitecore
    • Prefetch, data, item, html caches
  • Drupal
    • Performance caching (SQL queries stored)

Output Caching

  • IIS- – generate on request

App/Data Layer

  • Reducing database calls
  • Reducing API calls


  • Java based applications
  • Memory or disk


  • In memory, key/value store
  • Reduce database load
  • Not synchronized
  • Scalable separately

Let’s Not Fight

  • Not worth arguing about which is better
  • Memcached, Redis, Mongo
  • All are good


  • Redis
  • Firebase
  • Stored procedures – reduce network bandwith by calling short sproc rather than sending long query


  • Invalidating stale data

Caching Procedures

  • Only two things you’ll really need to do with caching
    • Populating
    • Invalidating

Debugging, need to remind people to clear their cache

  • [Sean] But should users have to worry about this? If you need to have them clear cache, then something’s not working properly

Populating Caches

  • Pull based – cache tool pulls from your server
  • Push based – your code has to push out data to the cache

Cache clearing

  • Staggered approaches
  • Clearing individual items
  • Using APIs and automation


That Conference 2018 – Securing Your ASP.NET Core Applications

That Conference 2018, Kalahari Resort, Lake Delton, WI
Securing Your ASP.NET Core Applications – Cecil Phillip

Day 3, 8 Aug 2018  1:00 PM

Disclaimer: This post contains my own thoughts and notes based on attending That Conference 2018 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of the speakers.

Executive Summary

  • Quick review of authentication pipeline
  • Various options for authentication

ASP.NET Core 2

  • Cross platform web framework
  • Targets .NET Standard 2.0
  • Introduces Razor Pages
  • SignalR Core available
  • ASP.NET Core 2.1 out now

Middleware Pipeline

  • diagram

Application Startup

  • Startup.cs
  • Configure takes IApplicationBuilder, IHostingEnvironment
  • app.UserXyz, app.UsePdq
  • The order of middleware matters


  • In VStudio, two servers
    • IIS Express
      • Enable SSL in properties
    • Kestrel – cross-platform
      • Have to use .NET CLI tool
      • dotnet dev-certs https –trust
      • Generates self-signed cert that’s automatically trusted
      • This cert doesn’t appear in cert manager
      • MMC – add snap-in, Certificates snap-in, My user account
      • Now looking at certs for the current user only
      • Now you see the dev cert that we just created
  • When you run, you fire up 2 endpoints–HTTP, HTTPS–that it’s listening too
  • Remove cert
    • dotnet dev-certs https –clean
  • Do not use this dev cert in production
    • Only for local development


  • Many options, i.e. middleware
    • Cookies
    • Twitter
    • Google
    • JWT Tokens
    • Facebook
    • OpenID Connect
    • Microsoft Accounts
    • Custom
    • Windows

Cookie Authentication Demo

  • In ConfigureServices, services.AddAuthentication
  • .AddCookie
  • In Configure, do app.UseAuthentication
    • Need to do this before UseMvcWithDefaultRoute
  • Mvc is a “terminating middleware”–stuff after it won’t run
  • Controller code
    • Login action, with LoginViewModel
    • Create ClaimsIdentity with a Claim
    • Pass in to HttpContext.SignInAsync
  • Back in ConfigureServices
    • .AddCookie takes opts with authentication events
    • We can handle various events as part of pipeline
      • Kick out existing logged in user

Twitter Authentication Demo

  • .AddAuthentication, AddCookie, AddTwitter (pass in client ID and secret)
  • Still just do app.UseAuthentication in Configure


  • Manage user secrets
  • Lives in app profile
  • JSON data with different secrets, e.g. Twitter-ClientSecret
  • (or) dotnet user-secrets
  • Roaming, so it will synch across profiles
  • BuildWebHost doesn’t do anything special to get secrets info
  • Configuration passed in to Startup (DI)
    • You can just ask it for secret, with [“xxx”]
  • In production
    • In Azure, have Azure key Vault
    • Can also create certificates
    • In application, you can specify Azure Key Value as a source of configuration
    • builder.AddAzureKeyValue (off .ConfigureAppConfiguration, in BuildWebHost
    • Register your app with Azure Key Vault–and perms, what can you do
    • Also supports versioning of secrets
  • What to put in Azure Key Vault
    • URL of SQL Server, web server URI
    • Connection strings
    • Secrets
  • You need secret to talk to key vault??
    • Yes, ID/Secret, hard-coded
    • OR create cert, associate with app in Azure App Services
  • You “compose” configuration
    • Settings come from various places

ASP.NET Identity

  • User management framework
  • Get bunch of stuff out of the box
  • Register
    • E-mail, password, Register button
  • Identity using EF, which uses migrations to ensure database is what you expect
  • You get Manage User feature
  • Authenticator app support
    • Little app on your phone to do 2-factor
  • Associate Google Authenticator app on phone to your application
  • Scan QR code with your phone, get #, enter that number
  • Also gives you recovery codes, for account recovery
    • You use one at a time and that code becomes invalid

Azure AD B2C

  • Create tenant, then go to that tenant
  • Register applications for that tenant
  • Identify providers
  • Can see users
  • Add to application (AD B2C)
    • New Project, Change Authentication
    • Individual user accounts – ASP.NET Identify
    • Individual user accounts, Connet to existing user store in the cloud
    • Add info for AD B2C, get domain name
    • Enter application ID
    • Reply URL–can default to localhost
    • Sign-up or Sign-in Policy–create one in Azure, give it name
      • Can have one or more policies for your application
      • E.g. E-mail sign-up
      • Application claims (in policy)
  • Run application that uses AD B2C
  • Login / signup, you go out to AD B2C page on Azure
    • E-mail verification code
    • Additional metadata fields, e.g. Job Title
  • User profiles in Azure, after they sign up

In code

  • User.Identities.First().Claims — a bunch of key/val pairs


That Conference 2018 – Tips & Tricks for a Successful Android Application

That Conference 2018, Kalahari Resort, Lake Delton, WI
Tips & Tricks for a Successful Android Application – Jorge Coca

Day 3, 8 Aug 2018  10:30 AM

Disclaimer: This post contains my own thoughts and notes based on attending That Conference 2018 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of the speakers.

Executive Summary

  • History of Android
  • Some cross-platform options (code sharing)
  • Some specific notes on Kotlin



  • App being used


Android was originally an OS for cameras

  • Not for smartphones
  • Google acquired Android to do a smartphone



  • Cupcake, Donut – Apr 2009
    • Linux kernel
    • Java, Eclipse ADT
    • Main widgets & SDK components
    • Gesture framework
  • Eclair, Oct 2009
    • Multi account
    • Bluetooth
    • Multitouch
  • Froyo, May 2010
    • Chrome (engine for web views)
    • Push notifications
    • Flash, GIFs
    • Improved market
  • Gingerbread, Dec 2010
    • NFC
    • Improved UI
    • Support for front camera
    • Nexus One
  • Honeycomb, Feb 2011
    • Big milestone
    • Optimized for tablet support
    • Holo interface
    • Welcome Fragments  (nobody likes them)
  • Ice Cream Sandwich, Oct 2011
    • Holo for phones
    • Major update of the OS
    • Editor’s choice
  • Jelly Bean, Jun 2012
    • Performance
    • Support library
    • Dev focus on quality (tools)
  • KitKat, Oct 2013
    • Refreshed interface
    • Android Wear
    • Nexus 5
    • Android Studio
    • Gradle – build tool
  • Lollipop, Nov 2014
    • Material Design – layers of paper
    • Dalvik
    • WebView distributed over PlayStore
    • Dev focus on performance
    • Android One
  • Marshmallow, Oct 2015
    • Android for Work
    • Doze
    • Fingerprint
    • Runtime permissions
    • Batter optimizations
  • Nougat, Aug 2016
    • Android beta
    • Daydream – VR
    • Multiwindow support
    • Picture in picture
  • Oreo, Aug 2017
    • Kotlin
    • Architecture components
    • Focus on modular architectures
    • Adaptive icons
    • Android Go (evolution of Android One)


Market Share

  • 2015, Android nearly 80% of smartphone market


Challenges (in order to be successful)

  • Clear goals and expectation
  • Invest your time and energy where it matters
  • Build for everyone – i.e. international
  • Crowded market. Be original
  • Be the first.. or be the best


Goals and expectations

  • Research your market
  • Measurable goals
  • Realistic exxpectations
  • Indie vs. small shop vs. corporation
  • Functionality vs design.. (or both)


Invest your time and energy where it matters

  • There’s cloud
  • And devices–iOS, Android
  • Don’t do the same work multiple times, i.e. across multiple devices
  • Cloud is the common layer–use it
  • Dedicate efforts to the main use case of your app
  • What can you share between iOS and Android?


Cross platform

  • Easiest: WebView
    • Security hole
  • WebView with native bridge: custom, Ionic, ..
  • Xamarin
    • Business logic in shared library, shared across devices
    • Xamarin works
  • Kotlin Multiplatform
    • Similar to Xamarin–business logic written just once
  • ReactNative
    • Widgets
  • Flutter


Android native

  • Stop using Eclipse
    • Android Studio has better tools, better effort
  • Stop using Java



  • Better develop experience
  • Interop with existing Java
  • Null safety
  • Google working on “Kotlifying” APIs
  • Easer to do more complex things
  • Don’t force unwrap (ignore null check)
  • Default parameter values–no need for factory constructors
  • Sealed classes to express more complex enums


Kotlin Tips

  • Data classes are your friends
  • Easy singletons with object
  • Synthetic extensions to avoid boilerplate



  • The smaller your Activities are, the better
  • The smaller your Fragments are, the better
  • The smaller your Services, the better
  • Remove business logic from SDK components
  • Only use libraries that make you feel comfortable
  • Do not overuse libraries
  • The smaller your APK is, the better (code for everyone)


That Conference 2018 – What’s New in C#7

That Conference 2018, Kalahari Resort, Lake Delton, WI
What’s New in C#7 – Jason Bock

Day 2, 7 Aug 2018  4:00 PM

Disclaimer: This post contains my own thoughts and notes based on attending That Conference 2018 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of the speakers.

Executive Summary

  • Brief review of history of C# versions
  • Lots of good new stuff in C# 7
  • Importance of C# and .NET now being open source

Language Evolution

  • C# – 2002, .NET 1.0
  • v1 – classes, evenst, properties
  • v2 – generics, partial types, anonymous methods, nullable types
  • v3 – LINQ, implicit types, extension methods, lambda expressions
  • v4 – dynamic binding, embedded interop types, named arguments
  • v5 – async/await, caller info attributes
  • v6 – Roslyn, exception filters, await in catch, auto prop initializer, default values for getters, expression-bodied members, string interpolation, null propagator, nameof
  • v7 – out variables, tuples, local functions, binary literals, ref returns/locals, throw expressions
  • v7.1
  • v7.2
  • v7.3

.NET Foundation

  • Foster open source development
  • Everything in .NET is now open source, on github
  • Contributors from both inside/outside MIcrosoft

.csproj file

  • Can target LangVersion, or latest

Binary digits, digit separators

  • Underscore in integer constant is separator–doesn’t do anything
  • Can do one or more underscores anywhere you like
  • 0b – binary literals

Local functions

  • Declare functions within functions
  • Compiled as private methods, so performance is the same as private methods

Out var

  • Replaces big try/catch block
  • Or TryParse
  • 3rd way in C# 7 – declare out var directly in method call

Ref Returns and Locals

  • Copy semantics for structs
  • Traditional list, indexer returns element, copied if element is value typed
  • Indexer can use ref keyword to pass element back by reference
    • For value typed objects, you get a reference to the value-typed object
  • Far faster (if elements are large)
  • Where you assign the element, you also use ref keyword

Pattern Matching

  • Using switch statement
  • Pass in parameter of parent type, then case on child type
  • Can also add when clause to trigger on stuff specific to that subtype
  • default case can be anywhere
  • case null


  • Not Item1, Item2 syntax from v5
  • Lets say that you want to pass two values back out of a function
  • public (int, int) ReturnTwoInts() { … }
  • Maps to ValueTuple, which has Item1, Item2, etc.
  • Can do named values
  • public (int x, int y) ReturnTwoInts
    • Can now ref result.x, result.y
  • Calling it
    • (var x, var y) = ReturnTwoInts()
  • Can use _ to indicate you don’t care
  • Deconstruct method – pull data out as tuple (?)
  • Can use tuples as concrete types in generics
  • Assign multiple properties in a single line of code with a tuple


  • Task is a reference type, but you might want a value-typed task for performance
  • ValueTask<T> is just a struct that does everything that a Task does
  • You’d use this only if you really need the added performance

Expression bodied members

  • Define wherever you like, not just read-only properties

[C# 7.1]

async main method

Default literals

  • Instead of default(int), you can infer the type of the default
  • So just use default keyword, type is inferred

[C# 7.2]

readonly struct


  • Look at chunk of memory
  • “Safe” way to read/write direct memory
  • e.g. “11,22” .AsSpan()
  • .Slice instead of Substring
  • No allocations
  • More performant

Constraint Generic

  • To enum type, to delegate type
  • where T : Enum

Compare Tuples

  • Equality semantics is correct

Backing field not serialized

  • On auto property, do [field: NonSerialized]

Future Directions

  • Ranges – foreach, in 5..10
  • Default Interface Methods – default implementation for a method on an interface
    • Looks odd
  • Nullable reference types
    • Have to opt-in, to avoid breaks
    • Once opt-in, MyClass mc would be non-nullable
    • Have to do MyClass? to get nullable
    • n!.Length – don’t worry about null-check
  • async streams – async enumerator
  • Generic attributes – e.g. [MyAttribute<int>]
  • Records and with expressions
  • Shapes and extensions
    • Mads T
    • Extensions everywhere – e.g. properties


Q: Isn’t this scary / dangerous? What is the main use case?

A: Multiple return values, e.g. int.Parse that is more elegant because it returns multiple things. Helps to avoid defining little objects designed just to pass data around between methods

That Conference 2018 – WebAssembly: The New EndGame?

That Conference 2018, Kalahari Resort, Lake Delton, WI
WebAssembly: The New Endgame? – David Pine

Day 2, 7 Aug 2018  2:30 PM

Disclaimer: This post contains my own thoughts and notes based on attending That Conference 2018 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of the speakers.

Executive Summary

  • WebAssembly allows writing high-level source code and compiling to a binary format that runs in execution engine on the client
  • Allows doing C#, for example, in browser
  • Blazor works with Mono to allow .NET on client, including Razor syntax


  • Engines for WebAssembly


  • Binary instruction for a stack-based virtual machine
  • Binary
    • AST (Abstract Syntax Tree)
    • Stored as binary
  • Stack-based
    • Pushing and Popping onto stack


  • Binary execution format for web


  • Mobile and IoT


  • Portable target compilation of high-level languages
  • For C, C++, C#, Rust, Go


  • Compile C#, target WASM, you get binary file
  • File can run in your browser


  • Game
  • In browser debug, you see demo.wasm and not much else

Chrome has it

  • What about other platforms?
  • Big movement, WebAssembly now supported everywhere
  • W3C – World Wide Web Consortium

Text Format (.wat)

  • There’s a text-format human readable version of the final assembly
  • Hard to read, since it’s really the compiled output

What it is not

  • Not assembly-level CPU-specific machine code
    • Doesn’t run on the CPU but runs in browser’s execution engine
    • But you get near-native performance, since it’s close to the metal
  • Not a 3rd-party plugin
    • WebAssembly runs in same sandbox as JavaScript
  • Not versioned
    • Backwards-compatible
  • Not JavaScript replacement
    • WA plays nicely with JS
  • Not a programming language
    • If you hand-coded .WAT files, it would be
    • But it’s really just a format or compilation target
  • Not the ideal tool for every web project
    • Different tools, e.g. JavaScript, C, to do HTTP request


  • Tool for compiling to WASM

Demo: Emscripten

  • emcc
  • Takes C source file as input (e.g. hello.c)
  • Target WASM
  • Run output in browser–we get console output in the browser

WASM Explorer / Fiddle

  • Call WASM assembly from JavaScript

Use Cases

  • Games, rich client, etc.

Hanselman interview of Steve Sanderson

  • Web development has been constrained because everything has had to be in JavaScript
  • Web development will be able to grow up and mature a bit

My interview with Sanderson

  • Give developers a wider choices of languages and platforms
  • Industry healthier if multiple paradigms catered to


  • Mono Runtime
    • Cross-platform .NET runtime
    • Using it now for Blazor


  • Browser + Razor
  • Experimental project at the moment
  • Not yet a committed product

How Blazor works

  • Dev time
    • C# / Razor source files
  • Runtime in browser
    • mono.wasm – WebAssembly binary executed natively
    • Browser APIs – visible DOM, HTTP requests, etc
    • YourApp.wasm – WebAssembly version of your library

Demo – Blazor

  • Project template in VStudio
  • ASP.NET Core Hosted
  • You get Client stuff and Server stuff, as well as Shared stuff
  • Shared library has web objects shared across server and client
  • Template gives you a simple multi-page web site with a few things
  • Fetch some data, click a button, etc.
  • Server has controller that returns some basic data
  • Razor syntax that turns into HTML
  • Inject HttpClient into component on client

Look at code for Blazor

  • Debug C# code in browser
    • Hit breakpoint after interacting with something in the browser
  • Program.cs with main entrypoint
  • CreateHostBuilder
  • Wire up various services
  • Add component (app)
  • Standard markup with Razor binding to C# object (model)

Other debugging

  • Currently not pre-compilation, but running in interpreted mode
  • Full-on .NET DLLs on client, e.g. mscorlib
  • For small app, we’re at 3.5 MB
  • But this will get optimized

Mono.wasm – is the .NET runtime running in a WebAssembly


With Unity, can target WASM

  • Unity in browser

That Conference 2018 – Design Patterns: Not Just for Architects

That Conference 2018, Kalahari Resort, Lake Delton, WI
Design Patterns: Not Just for Architects – Jeremy Clark

Day 2, 7 Aug 2018  1:00 PM

Disclaimer: This post contains my own thoughts and notes based on attending That Conference 2018 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of the speakers.

Executive Summary

  • There exist lots of design patterns that have been defined
  • We already use many of these without realizing it
  • Worth learning them–helps in communication
  • Examples of several patterns in C#


Goal: We’re already using design patterns, so worth putting a name on them


What are Design Patterns?

  • (Christopher Alexander quote)
  • Describes solution in a way that you can use it over and over again


Gang of Four book (GoF)

  • Gamma, Helm, Johnson, Vlissides
  • “Serious developer” needs to have this
  • Still relevant?  Yes
  • Examples in C++ and Smalltalk


Anatomy of a Design Pattern

  • Pattern Name
    • Unique way of referring to pattern
  • Problem
    • Problem that occurs over and over again
  • Solution
    • “Core” of the solution
    • Example implementations are not solutions
  • Consequences
    • Pros and cons
    • Things to watch out for


GoF Patterns

  • 23 different patterns
  • Categories
    • Creational
    • Structural
    • Behavioral
  • Book is a bit academic
    • Go through it at some point in your career
    • “You’re not ready for it yet”


Good starting point

  • Head First Design Patterns – Freeman, Freeman
  • Covers 12 of the GoF patterns
    • Same descriptions
    • Just explains it in a more approachable way
  • Examples in Java
    • But pretty general, so ok
    • Online, translations into various programming languages


Why Should We Care?

  • These are well-described solutions
  • Shared vocabulary
    • Easier to talk with other devs
  • Concise language
    • Quicker/shorter to just mention the pattern, rather than describing it in detail
  • Think in design rather than implementation
  • Encourage other developers to learn patterns


Observer pattern

  • When object changes state, dependent objects notified automatically
  • Publish-subscribe relationship


Real World Observer

  • Twitter – someone tweets, subscribers are notified


Implementation of Observer (C#)

  • Event handlers on button
  • This is ubiquitous in C# and in frameworks
  • Problem => Pattern => implementation of the pattern
    • E.g. pubsub => Observer pattern => event handlers
  • Prism, event aggregator
    • Publisher, subscribers don’t know about each other
  • .NET 4.0 – IObserver<T>
  • Consequences
    • I don’t know how many times I’ll be notified
    • Don’t know how frequently I’ll be notified
    • Don’t know if we’ll ever be notified


Iterator Pattern

  • Access elements of object sequentially without knowing about implementation of the thing
  • Get next item, stops at end
  • Real-world: Channel up button on TV Remote
  • In C#, foreach loop uses the iterator


Implementation of Iterator (C#)

  • Get List<T>, case to IEnumerable<T>
  • IEnumerable<T> says that object supports get next element (foreach)
  • All collections in .NET implement IEnumerable<T>
  • Nice that this is built into .NET (C#)


Facade Pattern

  • Unified interface for a set of interfaces in a sub-system
  • Higher-level interface makes things easier to use
  • Wrap complex stuff in simpler API


Real World Facade

  • Universal remote control wrapping access to multiple devices


Facade Implementation

  • foreach loop is also an example of facade
  • GetEnumerator
  • while (enumerator.MoveNext()) … do something with enumerator.Current()
  • foreach is a nice wrapper around this
  • Consequences
    • We might lose functionality that lower level stuff has
    • E.g. foreach doesn’t give access to Reset() method


Chain of Responsibility

  • Avoid coupling sender to receiver
  • Giving more than one object a chance to handle the request
  • Pass request along thru children until somebody handles it


Real-world example

  • Tech Support – first line, person asks questions
    • If not, passes to next person, more detailed look at your question


Chain of Responsibility Implementation

  • Throw exception
  • Catch certain types of exceptions at certain levels in call stack
  • If not caught at one level, it propagates up to the next level
  • Consequences
    • What is nobody handles the message?


Proxy Pattern

  • Provide surrogate for another object to control access to it
  • Example: Power of Attorney
    • One person makes another their proxy
  • Surrogate vs. placeholder
    • Placeholder–thumbnail or icon that only loads something when you click it
    • Good idea in mobile apps–delay download of some stuff, in case you have slow connection


Proxy Pattern Implementation

  • Web API service, controller with Get method
  • Get collection, return via service
  • Can create proxy service class that can call the service
    • HTTP clients
  • Use the proxy in the same way that you’d treat the original class
  • Consequences
    • Hides what’s really going on with the underlying object


A Million Implementations

  • Use over and over