Top 7 Lessons From My First Big Silverlight Project Benjamin Day Benjamin Day Consulting, Inc.

Slides:



Advertisements
Similar presentations
Test Automation: Coded UI Test
Advertisements

Design Principles & Patterns
Software Testing with Visual Studio 2013 & Team Foundation Server 2013 Benjamin Day.
Real World Scrum with TFS2013 Benjamin Day. Brookline, MA Consultant, Coach, & Trainer Microsoft MVP for Visual Studio ALM Team Foundation Server, Software.
How to be a C# ninja in 10 easy steps. Benjamin Day.
Or How I Learned to Stop Worrying and Love the Binding Bryan Anderson.
Enterprise Smart Clients Architecture, Patterns, Design, Best Practices Keith Elder Manager, Sr. Software Engineer Quicken Loans Blog:
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day benday.com |
Team Foundation Server 2010 Builds: Understand, Configure, and Customize Benjamin Day benday.com |
Microsoft Focus & Expertise We have a world-class team of Microsoft experts that can make any other platform integrate better with an existing enterprise.
WCF RIA Services - Querying and Updating Data SILVERLIGHTSHOW.NET WEBINARS SERIES BRIAN NOYES, CHIEF ARCHITECT, IDESIGN INC 2 FEB 2011.
Design Patterns for MVVM Unit Testing & Testability Benjamin Day.
Real world Windows Phone development Igor
Building Silverlight Applications Using the MVVM pattern An Introduction by Peter Messenger Senior Developer – Qmastor
N-Tier Architecture.
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day.
10 Ways to Get Your Project Started Right Benjamin Day.
Presenter - Donn Felker.  Senior Consultant for Microsoft Gold Certified Partner- Statêra.  8 years of experience in developing and architecting enterprise.
@benday #vslive Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
Doing Something Useful with Enterprise Library 3.0 Benjamin Day Level: Intermediate.
CS378 - Mobile Computing App Project Overview. App Project Teams of 2 or 3 students Develop an Android application of your choosing subject to instructor.
@benday #vslive Automated Build, Test & Deploy with TFS, ASP.NET, and SQL Server Benjamin
Chris Hance. Why “Re-”evolving?  NIH Epidemic  My name is Chris, and I’m a… VB6 Coder  YAGNI.
Building an Offline Smart Client using Domain-Driven Design Principles Tim McCarthy.
Top 10 Ways to Go from Good to Great Scrum Master Benjamin Day.
Team Foundation Server 2012 Builds: Understand, Configure, and Customize Benjamin Day.
© ALEXANDRE CUVA  VERSION 2.00 Test Driven Design.
Software Design 4.1 Tell, Don't Ask l Tell objects what you want them to do, do not ask questions about state, make a decision, then tell them what to.
1 Performance Optimization In QTP Execution Over Video Automation Testing Speaker : Krishnesh Sasiyuthaman Nair Date : 10/05/2012.
How to be a C# ninja in 10 easy steps Benjamin Day.
Alcatel-Lucent CDC Workshop, Coaching & Knowledge Transfer Architecture.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans.
Zero to Hero: Untested to Tested with Visual Studio Fakes Benjamin
Building State of the art presentation tiers Nauzad Kapadia
CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
Real World SQL Server Data Tools Benjamin
To Git or Not to Git for Enterprise Development Benjamin Edward Thomson
Building Robust, Maintainable Coded UI Tests with Visual Studio 2010 Brian Keller Sr. Technical Evangelist – Visual Studio ALM
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
Eliminate Team Build Headaches with Unit Tests, WiX and Virtualization Benjamin Day
Spaso Lazarević Microsoft MVP Nova banka ad Banja Luka Building business application using Visual Studio 2013 LightSwitch.
Programming with MVVM Miguel A. Castro Architect -
Principled N-Tier Design or, a Solution to the Solution Problem Steve | ardalis.com Telerik, Inc.
Benjamin Day Get Good at DevOps: Feature Flag Deployments with ASP.NET, WebAPI, & JavaScript.
Benjamin Unit Testing & Test-Driven Development for Mere Mortals.
Benjamin Day Role-based Security Stinks: Better Authorization in ASP.NET.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Intro To MVC Architecture.
Beyond Basic Unit Testing: Mocks, Stubs, User Interfaces, and Refactoring for Testability Benjamin Day
Adam Schultz MVVM and WPF. MVVM Model, View, ViewModel A software architecture designed to separate out User Interface design, Business Logic, and Data.
Introduction ITEC 420.
DevOps with ASP.NET Core and Entity Framework Core
Real world Windows Phone development
Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
N-Tier Architecture.
Software Architecture & Difference from Design
Building Custom Workflows
Top 10 Mistakes in Unit Testing
Entity Framework Core for Enterprise Applications
Unit Testing & Test-Driven Development for Mere Mortals
Unit Testing & Test-Driven Development for Mere Mortals
Get Good at DevOps: Feature Flag Deployments with ASP
Zero to Hero: Untested to Tested with Visual Studio Fakes
Unit Testing & Test-Driven Development for Mere Mortals
Real World Scrum with TFS & VSTS / Azure DevOps
2/24/2019 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Entity Framework Core for Enterprise Applications
Implementing Security in ASP.NET Core: Claims, Patterns, and Policies
Developing and testing enterprise Java applications
Presentation transcript:

Top 7 Lessons From My First Big Silverlight Project Benjamin Day Benjamin Day Consulting, Inc.

About: Benjamin Day Brookline, MA Consultant, Coach, Trainer Microsoft MVP for Visual Studio ALM Team Foundation Server, Software Testing, Architecture, Windows Azure TechEd, VSLive, DevTeach Visual Studio Magazine, Redmond Developer News Scrum.org Classes –Professional Scrum Developer (PSD) –Professional Scrum Foundations (PSF)

OVERVIEW

Goals Call out the pitfalls Learn from my mistakes Silverlight pain points Hopefully, avoid the pitfalls

Regulatory application for a Federal agency As of 1/15/2011: –Silverlight 1,557 *.cs files 11 MB of *.cs –Service code 507 *.cs files 2.3 MB of *.cs Approximately 12 months of development Background

It’s reasonably large.

Silverlight 4 GalaSoft MvvmLight Microsoft Unity.NET 4 WCF Enterprise Library 5.0 Data Access Block SQL Server 2008 R2 Windows 2008 R2 Visual Studio 2010 Team Foundation Server 2010 Technologies

We’re not using RIA Services.

If you’re using RIA, that’s OK.

(You’re not necessarily a bad person.)

In software, technologies that are supposed to save me time usually don't. They steal short- term time savings from long-term maintenance. My $0.02 on RIA Services.

On enterprise projects, time to market matters but not as much as the long-term maintenance and operational concerns of the app. My $0.02 on RIA Services.

If time to market matters more than maintenance or operations, RIA is an option. RIA introduces tight coupling between the client and server My $0.02 on RIA Services.

THE LESSONS.

The 7 Lessons. 1. Client-side & Server-side: It’s 2 applications. 2. Unit test, unit test, unit test. 3. Async WCF calls dictate your architecture. 4. Repository & Adapter patterns are your friend. 5. No shortcuts: Keep your ViewModels & Models separate. 6. Primitive Obsession in your ViewModel. 7. x:Name is a code smell.

Lesson 1: It’s 2 applications.

Your app. Let’s say you have a Silverlight UI Calls back to some WCF endpoints WCF services write data in to a database You’re probably writing all this at the same time Feels like you’re writing one application.

Client-side & Server-side: They’re 2 applications Service Service-Oriented Application (SOA) Uses a database for it’s persistence “Domain Model” implementation User interface is a collection of WCF endpoints Client Runs on a desktop machine Silverlight UI Has it’s own object model Uses WCF services for persistence

Why do I think this? When data is returned via WCF, you’re leaving the AppDomain Objects on the server are converted to XML XML is hierarchical When you’re writing WCF applications, it’s a mistake to think that you’re returning objects. Your application is actually “message- oriented”

Why do I think this? Difficult to share code on both sides of the wire You’re writing both apps at the same time but the server-side code doesn’t need the Silverlight code. Silverlight definitely needs the service code.

Benefits of thinking about 2 apps It’s like building a tunnel under a mountain. Meet in the middle –Design the endpoints –Server team works on server code –Client team works on client code Find problems faster Iterate with your customer faster

Benefits of thinking about 2 apps Code to abstractions  Fewer dependencies  Loosely coupled  Easier to test

Lesson 2: Unit test, unit test, unit test.

Disclaimer: I’m obsessed with unit testing.

Why unit test? What’s “done” stays “done”. You find problems early. Bugs stay dead. Refactoring is painless. If your application is large, it’s tough to know when you’ve broken something obscure. Unit tests tell you when you’ve broken your app.

What do I test? Silverlight ViewModels –Operations –Commands –INotifyPropertyChanged –Progress Bars –Show/Hide Logic –Login/Logout Domain Models Domain Model Services WCF logic –I don’t test making WCF calls from Silverlight to the WCF Services Utility methods Server-side Data access code –aka. Repositories Domain Model Domain Model Services Services –Direct calls without WCF –Calls through WCF

Which unit test frameworks? Server-side: Visual Studio 2010 (MSTest) Silverlight: Silverlight Control Toolkit Unit Test Framework –It’s not great. –Better than nothing. –At least it runs in Silverlight.

Benefits of “2 applications” + unit testing Thinking of 2 apps helps isolate problems Are the service unit tests passing? Are the Silverlight unit tests passing? Silverlight Passing? Services Passing? Conclusion YesNoService problem NoYesSilverlight problem Yes New problem No Whew! $%^& is broken.

Tip: Don’t write new code if the tests are broken. Always code on top of a known good state If you make changes and the tests stop passing, it’s your fault. –Do your team a favor. Please, don’t check in.

Side note: TFS 2010 Gated Check-in Continuous integration on steroids. Check in goes to a shelveset A build kicks off that compiles the shelved code Runs unit tests Compile fails or unit testing fails  your code doesn’t get checked in No more broken builds!

Lesson 3: Async WCF rules your architecture.

(BTW…)

(Just between you and me.)

(This one nearly killed me.)

My initial client-side architecture.

My architecture after Async WCF beat me up and ate my lunch.

Network traffic in Silverlight It has to be async. If it isn’t, the UI thread locks…forever.

Async Kills Your Repository methods can’t return populated objects  must return void Exception handling is hard –Work happens on a different thread –Exceptions can’t “bubble up” the stack You could have your *.xaml.cs handle the callbacks –Ugly –Violates “separation of concerns”

My Solution: ReturnResult My Solution: ReturnResult “Virtual” call stack Notify(Exception) or Notify(T)

The “glue” between method calls

Reactive Extensions for.NET us/devlabs/ee aspx us/devlabs/ee aspx Alternate Solution

Lesson 4: Repository & Adapter Patterns are your friend

What is Repository?

The Repository Pattern “Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.” – tmlhttp://martinfowler.com/eaaCatalog/repository.h tml Encapsulates the logic of getting things saved and retrieved

Synchronous Repository

Synchronous SQL Server & WCF

A Big Picture

Async Repository

What is Adapter?

Adapter Pattern “…converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.” from “Head First Design Patterns” by Elisabeth & Eric Freeman

My version of Adapter Pattern Take object of Type A and convert it in to object of Type B

Why are these patterns your friend? If you “Add Service Reference”, these are *NOT* your Models or ViewModels –(I know it might be tempting.) –(Remember, it’s 2 applications.) $0.02, you want your own Models and ViewModels –Breaks the dependency on the WCF services You’ll convert to/from the Service Reference objects

Why are these patterns your friend? Help focus your mind Better design Help contain bugs –These conversions to/from will be buggy Help localize change –Service endpoint designs will change often Unit test the conversions separately –(Remember it’s a “unit” test.)

SOLID Principles Robert C. Martin ArticleS.UncleBob.PrinciplesOfOod ArticleS.UncleBob.PrinciplesOfOod

SOLID Principles of Class Design PrinciplePurpose Single ResponsibilityA class should have one, and only one, reason to change. Open ClosedYou should be able to extend a class’s behavior without modifying it. Liskov SubstitutionDerived classes must be substitutable for their base classes. Interface SegregationMake fine grained interfaces that are client specific. Dependency InversionDepend on abstractions, not on concretions.

Single Responsibility Principle Poster by Derick Bailey

Keep the Adapt separated from the Retrieve Two classes –Repository knows how to talk to the WCF service –Adapter knows how to turn the Service Reference types into Models

Lesson 5: No shortcuts: Keep your ViewModels & Models separate.

No shortcuts: Keep your ViewModels & Models separate. It will be tempting to have your Repository/Adapter layer create ViewModels –(Don’t.) There’s a reason why it’s called Model-View-ViewModel

Why keep Model and ViewModel separated? ViewModel is a user interface design Model is the state of your application –aka. “Domain Model” pattern ViewModel advocates for the UI –1-to-1 between a ViewModel and a *.xaml file –Might reference multiple Models Don’t have the ViewModel fields directly update the Model.

It’s all about the Cancel button. If you’re “two way” data bound, How do you undo?

Cancel: ViewModel wraps Model ViewModel populates itself from the Model User edits the screen, ViewModel gets updated Model doesn’t get changed until Save button is clicked. Model is The Boss.

Lesson 6: Primitive Obsession in your ViewModel.

Primitive Obsession James Shore’s “Primitive Obsession” –Too many plain scalar values –Phone number isn’t really just a string – Validation in the get / set properties is ok but is phone number validation really the responsibility of the Person class?

Coarse-Grained vs. Fine-Grained Object Model James Shore blog entry talks about Responsibilities –Fine-grained = More object-oriented –Data and properties are split into actual responsibilities I’m concerned about Responsibilities + Code Duplication + Simplicity

Provides common functionality for a property on a ViewModel ViewModelField<T>

With & Without ViewModelField With & Without ViewModelField

Are your ViewModel properties Coarse or Fine? Fine-grained gives you room to grow ViewModelField Create custom controls that know how to talk to your ViewModelFields –Simplified binding expressions Add features later –Field validation later –Security

Article: 6 MVVM Tips

Lesson 7: x:Name is a code smell.

An indication that there *MIGHT* be a problem –Quality –Maintenance –Performance –Etc… What’s a ‘Code Smell’?

Bad for ViewModel & UnitTesting Named Values populated by get/set statements Implies a lot of code in the “code behind” (*.xaml.cs) Not Named Populated via binding expressions ViewModel-centric Minimal *.xaml.cs code * BETTER TESTABILITY *

CodedUI Tests and Manual Test Automation in Microsoft Test Manager (MTM) & VS2010 Ultimate –Visual Studio 2010 Feature Pack 2 –Requires controls to be uniquely named in order to automate simulated user interactions Animation Designers in Blend –(I have been told this but have not verified this myself.) Where my opinion breaks down…

Remember: A “smell” is not necessarily bad.

Bad Smell This is garbage. Do not eat. Smells awful.

This is Langres From Champagne- Adrenne region of France Cow’s milk Tastes awesome Smells fairly awful Good Smell Photo: Benjamin Day, 12/14/2008

Cheese is controlled rot. It’s a way of preserving food. It’s supposed to be that way. Garbage is garbage. Good Smell vs. Bad Smell

The Recap.

The 7 Lessons. 1. Client-side & Server-side: It’s 2 applications. 2. Unit test, unit test, unit test. 3. Async WCF calls dictate your architecture. 4. Repository & Adapter patterns are your friend. 5. No shortcuts: Keep your ViewModels & Models separate. 6. Primitive Obsession in your ViewModel. 7. x:Name is a code smell.

Any last questions?

Goals Call out the pitfalls Learn from my mistakes Silverlight pain points Hopefully, avoid the pitfalls

Thank you. |