sander hoogendoorn principal technology officer capgemini the netherlands session code: arc303

97
How Frameworks Can Kill Your Project And Patterns Can Prevent You From Getting Killed Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Upload: willis-benson

Post on 13-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

How Frameworks Can Kill Your Project And Patterns Can Prevent You From Getting KilledSander HoogendoornPrincipal Technology OfficerCapgemini The Netherlands

SESSION CODE: ARC303

Page 2: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Sander HoogendoornCapgemini

Principal technology officer Agile thought leaderAccelerated Delivery Platform

OtherAuthor books (UML, agile) and articlesSpeaker at international conferencesMicrosoft Partner Advisory Council .NETColumnist several magazinesMember several editorial boards

Webwww.sanderhoogendoorn.comwww.smartusecase.comTwitter: @aahoogendoornLinkedIn: aahoogendoorn

Page 3: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Talk MyTalk = new Talk();

MyTalk.Subject != new Framework()

Page 4: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

if (MyTalk.Subject != new Framework()){

MyTalk.Subject = new List<Framework>();}

Page 5: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyTalk(t => t.Subject).Select(new Framework()).Discuss(new List<AntiPattern>).Discuss(new List<Pattern>).ShowSome(Code).HaveFun();

Page 6: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Gartner says …

Page 7: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyFirstSurvey

Page 8: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Hofstadter’s LawIt always takes longer than you expect, even when you take into account Hofstadter’s Law

Page 9: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyTalk(t => t.Subject).Select(new Framework()).Discuss(new List<AntiPattern>).Discuss(new List<Pattern>).ShowSome(Code).HaveFun();

Page 10: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Life is never easy …Frameworks, like pizzas, only come in only two sizes: too big and too small.

Page 11: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyFirstSurvey

Page 12: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyFirstSurvey

Page 13: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

What’s it gonna be?General Purpose Frameworks

Enterprise Library, Spring.Net, Castle, NakedObjects, ADF, SubSonic, …

Single goaled frameworks – verticals

Dependency injection: ObjectBuilder, Unity, Castle Windsor, (MEF)

Logging: Log4Net, Logging Block, Common.Logging

Exception handling: Exception Handling Block

Apect orientation: PostSharp, SetPoint

Search: Lucene.net, NLucene

Portals: DotNetNuke, Umbraco, Orchard CMS

Single goaled frameworks – architectural

User interface: Silverlight, ASP.NET MVC, WPF, ASP.NET Ajax, Spring MVC

Process: UI Process Application Block, WF

Domain: Entity Framework, NHibernate, NEO

Data: Entity Framework, Hibernate, Castle ActiveRecord, CSLA

Services: WCF, WCF RIA

Page 14: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Frameworks – www.codeplex.com

Page 15: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Frameworks – www.csharpopensource.com

Page 16: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Frameworks – Microsoft Enterprise Library

Page 17: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Frameworks – Project Castle

Page 18: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Don’t believe the hype – It’s a SQL

Page 19: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyFirstSurvey

Page 20: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Convincing the management to apply the framework (25.5 %)

Page 21: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Understanding the framework (56.4 %)

Page 22: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Convincing the developers to use the framework (23.6 %)

Page 23: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Training the developers (20 %)

Page 24: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

The eye of the tiger

Page 25: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyTalk(t => t.Subject).Select(new Framework()).Discuss(new List<AntiPattern>).Discuss(new List<Pattern>).ShowSome(Code).HaveFun();

Page 26: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

FrameworksThe way out of trouble is never as simple as the way in.

Page 27: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

So glad you made it!

What if we require additional features that aren’t covered by

our framework?

What if we decide that another framework might be better

than the one we’re using now?

What if the author of our favorite framework suddenly

stops developing it?

What if the framework contains bugs?

And what if the new version of our framework is implemented

totally different?

Page 28: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Pig & Chicken Architecture

Page 29: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Pigs & Chickens

An applicationdeveloper

A frameworkdeveloper

Page 30: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Pig & Chicken Architecture – Entity Framework

Page 31: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

KFC Architecture – Entity Framework

Page 32: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

KFC Architecture – Entity Framework

Page 33: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Letting the lunatics run the asylum

I don’t care if it works on your machine!We are not shipping your machine!

Here’s … beta!

Page 34: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Here’s Johnny! – ASP.NET MVC

Page 35: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Here’s Johnny! – ASP.NET MVC

Page 36: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Here’s Johnny! – StructureMap 2.5

Page 37: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Blog based documentation

Page 38: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

No strings attachedOnly in theory, practice and theory are the same

Page 39: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyFirstSurvey

Page 40: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Changing base classes – – NHibernate / Log4Net

Page 41: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Changing base classes – NHibernate / Log4Net

Page 42: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

If anything, dependencies will kill your project

Page 43: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Yes, your frameworks version too

Page 44: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

It ain’t over till it’s over

End of lifecycle?

Page 45: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Missing base classes – Workflow Foundation 4.0

Page 46: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Missing base classes – Workflow Foundation 4.0

Page 47: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyTalk(t => t.Subject).Select(new Framework()).Discuss(new List<AntiPattern>).Discuss(new List<Pattern>).ShowSome(Code).HaveFun();

Page 48: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

How to avoid getting killedSome basic patterns that might help you

Page 49: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

The good, the bad and the ugly Dependencies

Using frameworks is simply good, gringo

However, be very aware of dependencies

Minimize dependencies Frameworks reflect software architecture, not vice

versa

Define your own layer supertypes

Apply dependency injecton / extensibility

Apply additional patterns

Many more patterns, some very basic, will increase minimizing dependencies

Page 50: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Sound architectureArchitecture starts when you carefully put two bricks together. There it begins.

Page 51: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Software architectures …

Page 52: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Presentation

Process

Domain

Data / Services

Outside world

PagesUserControls

Panels

Use casesWorkflow

Domain objects / EntitiesFactories / Repositories

Enums / Value objects / Smart references[Mapping]

Service gatewaysService locators

[Mapping]

DatabasesServices / ESB

Peoplesoft SAP BizTalk Java

Software architecture vs frameworks

• Software architecture is leading• Layers, elements, responsibilities,

collaboration• Frameworks supports architecture!• Code reflects architecture

Page 53: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer supertypeFrom a programmer's point of viewthe user is a peripheral that types when you issue a read request.

Page 54: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype

What’s a layer supertype Ollie? Acts as a supertype for all types in its layer

All types inherit from the layer supertype

Well Stan, it’s characteristics are Name expresses common behaviour

Forces common features on all inherited types

Ideal starting point for services

Initially the layer supertype is empty

Reserve layer supertype for future additions

Extension methods don’t (always) help, you know

Page 55: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype – Interface?

Page 56: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype - Basic

Page 57: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype – ASP.NET MVC

Page 58: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype – ASP.NET MVC

Page 59: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype - Inherited

Page 60: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype - Inherited

Page 61: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype - Inherited

Page 62: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Layer Supertype – Defining services

Page 63: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyTalk(t => t.Subject).Select(new Framework()).Discuss(new List<AntiPattern>).Discuss(new List<Pattern>).ShowSome(Code).HaveFun();

Page 64: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

DescriptorAlways code as if the guy who ends up maintainingyour code will be a violent psychopath who knows where you live.

Page 65: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

I know nothing. I’m from Barcelona

What is the matterMister Fawlty?

The problem Manual, is that I want to use constants in my application

But I want to define them in my framework and extend them in my application

Enumeration won’t do – there’s no inheritance[PrincipalPermission(SecurityAction.Demand, Role = "Teller")]

Page 66: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Enum?

Page 67: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

String Collection

Page 68: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

I know nothing. I’m from Barcelona

Descriptor

Defines a restricted but application specific extendible list of definitions

Useful when Enums can not be inherited

Framework defines enumeration types that need to be extended in application code

Define layer supertype using reflection

Pre-define frequently used instances

[PrincipalPermission(SecurityAction.Demand, Roles.Teller)]

Page 69: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Descriptor Pattern – In use

Page 70: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Descriptor Pattern

DEMO

Page 71: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyFirstSurvey

Page 72: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Descriptor Pattern – Use in ASP.NET MVC

Page 73: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Descriptor Pattern – Use in ASP.NET MVC

Page 74: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Descriptor PatternIn ASP.NET MVC

DEMO

Page 75: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Dependency injection (DI)XML is like violence - if it doesn’t solve your problems, you are not using enough of it.

Page 76: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

DI? A new disease? What do you think it is?

Create true separation between definition and implementation, so that the two can vary independently and can be replaced easily

Looks like a typical case of dependency injection to me Call functionality without having to know

the actual implementation

Implement replaceable services

Apply implementations in different contexts

Plug-in services at run-time

So … Single topic services

Single or multiple implemenations need to be handled, which differs dependant on context, like with Windows API, logging or error handling

Unit testing

Page 77: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Different variations? Did you know that there are different types of this dependency injection?

Arggh…Yeah, sure. There’s Constructor injection

Property (setter) injection

And even manual injection

Extending MEF style? Who cares doc?

Page 78: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Dependency injectionConstructor injection, setter injection, manual injection

DEMO

Page 79: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Dependency injection – Configuration files

Yes, XML will hurt you too!

Page 80: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Manager – Provider"Teamwork is a lot of people doing what I say“

Page 81: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

TeamworkDefinition The manager-provider pattern creates a simple facade for a (set

of) interfaced implementation(s)

In practice Facade holding one or a collection of instances of a particular

interface

Methods to call methods from interface

At run-time, using dependency injection, actual implementation are injected

Useful when Generic services need to be called, which may have different

implementations

Manager prevents having to loop through each of a list of implementation

Flexibility to add or remove implementation without change the application code

Page 82: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Manager – ValidationManager

Page 83: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Manager – ValidationManager

Page 84: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Provider – IValidationHandler

Page 85: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Manager – ValidationManager

Page 86: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Client – A use case

Page 87: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Manager provider

DEMO

Page 88: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

The good, the bad and the ugly Dependencies

Using frameworks is simply good, gringo

However, be very aware of dependencies

Minimize dependencies Frameworks reflect software architecture, not vice

versa

Define your own layer supertypes

Apply dependency injecton / extensibility

Apply additional patterns

Many more patterns, some very basic, will increase minimizing dependencies

Page 89: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

if (MyFramework.AntiPatterns.Count > 3){

throw new FrameworkKilledProjectException();}

Page 90: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

catch(FrameworkKilledProjectException e){

MyFramework.Apply(List<Pattern>);}finally{

MyApplication.Coupling = Couplings.Loose;}

Page 91: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

MyTalk(t => t.Subject).Select(new Framework()).Discuss(new List<AntiPattern>).Discuss(new List<Pattern>).ShowSome(Code).HaveFun();

Page 92: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

References and questionswww.accelerateddeliveryplatform.comwww.sanderhoogendoorn.comorsander.hoogendoorn@capgemini.com LinkedIn: aahoogendoorn Twitter: @aahoogendoorn

Page 93: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Resources

www.microsoft.com/teched

Sessions On-Demand & Community Microsoft Certification & Training Resources

Resources for IT Professionals Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet http://microsoft.com/msdn

Learning

Page 94: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Complete an evaluation on CommNet and enter to win!

Page 95: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st

http://northamerica.msteched.com/registration

You can also register at the

North America 2011 kiosk located at registrationJoin us in Atlanta next year

Page 96: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 97: Sander Hoogendoorn Principal Technology Officer Capgemini The Netherlands SESSION CODE: ARC303

JUNE 7-10, 2010 | NEW ORLEANS, LA