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

Post on 13-Jan-2016

213 views 0 download

transcript

How Frameworks Can Kill Your Project And Patterns Can Prevent You From Getting KilledSander HoogendoornPrincipal Technology OfficerCapgemini 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

Talk MyTalk = new Talk();

MyTalk.Subject != new Framework()

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

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

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

Gartner says …

MyFirstSurvey

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

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

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

MyFirstSurvey

MyFirstSurvey

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

Frameworks – www.codeplex.com

Frameworks – www.csharpopensource.com

Frameworks – Microsoft Enterprise Library

Frameworks – Project Castle

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

MyFirstSurvey

Convincing the management to apply the framework (25.5 %)

Understanding the framework (56.4 %)

Convincing the developers to use the framework (23.6 %)

Training the developers (20 %)

The eye of the tiger

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

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

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?

Pig & Chicken Architecture

Pigs & Chickens

An applicationdeveloper

A frameworkdeveloper

Pig & Chicken Architecture – Entity Framework

KFC Architecture – Entity Framework

KFC Architecture – Entity Framework

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!

Here’s Johnny! – ASP.NET MVC

Here’s Johnny! – ASP.NET MVC

Here’s Johnny! – StructureMap 2.5

Blog based documentation

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

MyFirstSurvey

Changing base classes – – NHibernate / Log4Net

Changing base classes – NHibernate / Log4Net

If anything, dependencies will kill your project

Yes, your frameworks version too

It ain’t over till it’s over

End of lifecycle?

Missing base classes – Workflow Foundation 4.0

Missing base classes – Workflow Foundation 4.0

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

How to avoid getting killedSome basic patterns that might help you

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

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

Software architectures …

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

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

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

Layer Supertype – Interface?

Layer Supertype - Basic

Layer Supertype – ASP.NET MVC

Layer Supertype – ASP.NET MVC

Layer Supertype - Inherited

Layer Supertype - Inherited

Layer Supertype - Inherited

Layer Supertype – Defining services

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

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

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")]

Enum?

String Collection

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)]

Descriptor Pattern – In use

Descriptor Pattern

DEMO

MyFirstSurvey

Descriptor Pattern – Use in ASP.NET MVC

Descriptor Pattern – Use in ASP.NET MVC

Descriptor PatternIn ASP.NET MVC

DEMO

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

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

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?

Dependency injectionConstructor injection, setter injection, manual injection

DEMO

Dependency injection – Configuration files

Yes, XML will hurt you too!

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

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

Manager – ValidationManager

Manager – ValidationManager

Provider – IValidationHandler

Manager – ValidationManager

Client – A use case

Manager provider

DEMO

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

if (MyFramework.AntiPatterns.Count > 3){

throw new FrameworkKilledProjectException();}

catch(FrameworkKilledProjectException e){

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

MyApplication.Coupling = Couplings.Loose;}

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

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

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

Complete an evaluation on CommNet and enter to win!

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

© 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.

JUNE 7-10, 2010 | NEW ORLEANS, LA