This document discusses common ASP.NET design patterns. It provides an overview of several design patterns including singleton, factory, repository, dependency injection, and MVC. It also demonstrates these patterns in code examples and discusses when to use certain patterns over others. Real world examples are given and it encourages the use of design patterns to reduce coupling and improve code organization, testability, and maintenance.
14.
Shameless Plug:
But why would you
Telerik JustMock can be
intentionally write code
usedcan mocktest with
you to only and test
certainSingletons tools?
premium
45. Thanks!
• Find me at http://ardalis.com
• We’re hiring developers and trainers at
Telerik!
• http://telerik.com/company/careers.aspx
Editor's Notes
General, reusable solutions to common problemsNot a complete, finished solutionA template, recipe, or approach to solving certain problemsEach has a specific name, so we can discuss common elements of design using a common vocabulary
Learning anything – a musical chord, a martial arts technique, etc.Zero: You used a what? Never heard of it.Awakening:Wow, I just learned how XYZ pattern can improve my design. I’m not really sure where it would work in my code, but I’m definitely looking.Overzealous:I totally “get” the XYZ pattern; I’m adding it everywhere I can shoehorn it into my code. My design’s gonna be better now, for sure!Mastery: In response to some specific design pain points, the XYZ pattern was a logical next step and was achieved through a simple refactoring.
Design pattern names provide placeholders or complex abstractions and sets of refactorings. Consider the difference between:We have some tight coupling to the database here. We can probably fix it if we apply these refactorings;extract an interface, extract a method, Extract a class,Replace local with parameterORLet’s apply the Repository pattern to fix it.
It’s possible for the new Singleton(); line to be called more than once.
Apply patterns via refactoring,Not Big Design Up Front
Show the MvcMusicStore applicationHg clone https://hg.codeplex.com/forks/ssmith/mvcmusicstorerepositorypattern
Talk about the CacheDependencyBug in AdSignia and how it was introduced by moving a hard-coded instantiation to a parameter, and then fixed by replacing the parameter with a Factory (lambda).