TechEd 2013 11/17/2018 6:14 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Developer Fundamentals: The Series Calgary. NET User Group Feb SOLID Creating malleable software through design Simon Timms Microsoft MVP – ASP.net
Developer Fundamentals Series Testing – Nov. 26, 2014 SOLID – Feb. 26, 2015 Dependency Injection – June Source Control – Branching/Merging – July Putting It All Together – TBD
Simon Timms Senior .NET Dev – Pacesetter Directional Drilling @stimms TechEd 2013 11/17/2018 6:14 PM Simon Timms Senior .NET Dev – Pacesetter Directional Drilling In IT for over a decade (+/− few months) Microsoft MVP – ASP.NET/IIS Prolific Speaker and Community Involvement PRDC (many), AzureCamp, Local events Calgary .NET User Group – President Author Loves Development Polyglot Web apps, .NET back ends Visualization and Cloud http://linkd.in/15pYAWL @stimms http://blog.simontimms.com/about/ © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Dave White Principal Consultant – Depth Consulting @AgileRamblings In IT for over 15 years Microsoft MVP – Visual Studio ALM Kanban/Agile Evangelist, Speaker PRDC 2011, 2012, LKUK, Local events Program Director – KCP Program - LKU Professional Scrum Master Microsoft Platform Developer (C#, Web, WPF) http://linkd.in/giMxuw @AgileRamblings http://www.agileramblings.com
WHY?
Let’s take a step back What do we offer that off the shelf software doesn’t Why do any of us even have jobs? Why are companies investing in tools?
Because every business is different TechEd 2013 11/17/2018 6:14 PM Because every business is different © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
and every business is changing TechEd 2013 11/17/2018 6:14 PM and every business is changing LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Software needs to change too TechEd 2013 11/17/2018 6:14 PM Software needs to change too LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Badly Designed Software Rigid Unable to adapt to changing needs as a change affects other parts of the system Fragile Changes cause unexpected side effects somewhere else in the software Immobile Code cannot be reused in other parts of the system or in other systems
Object oriented programming TechEd 2013 11/17/2018 6:14 PM Object oriented programming Objects offer encapsulated, reusable functionality Couple data (state) with functionality (behaviour) Programming with objects is jolly hard LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
SOLID Principles of class design TechEd 2013 11/17/2018 6:14 PM SOLID Principles of class design Originally enumerated by Uncle Bob Martin LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
SOLID Single Responsibility Principle Open Closed Principle TechEd 2013 11/17/2018 6:14 PM SOLID Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Single Responsibility Principle Tom DeMarco Structured Analysis and Systems Specification
Single Responsibility Principle A class should have one, and only one, reason to change Classes that expose large number of external methods are likely to have many reasons to change
An example https://github.com/dotnet/corefx/blob/master/src/Microsof t.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
An example we can fix https://github.com/dpaquette/BugTracker.NET/blob/master/src/ BugTracker.Web/btnet/bug.cs
Open – Closed Principle TechEd 2013 11/17/2018 6:14 PM Open – Closed Principle Bertrand Meyers Robert C. Martin LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Open – Closed Principle TechEd 2013 11/17/2018 6:14 PM Open – Closed Principle A class should be open for extension and closed for modification When the business changes a new implementation should extend the existing functionality instead of changing it This limits the number of places in which code must change LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Open – Closed Principle TechEd 2013 11/17/2018 6:14 PM Open – Closed Principle Base classes should be largely abstract and become more well defined further down the stack LG hygiene and cosmetics Vivendi – water company Nintendo – playing card company © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Example Shape TechEd 2013 11/17/2018 6:14 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.
Liskov Substitution Barbra Liskov
Liskov Substitution Let q(x) be a property provable about objects x of type T. Then q(y) should be provable for objects y of type S, where S is a subtype of T. That is to say that you should be able to replace a class with its sub-class without changing the correctness of the programme
An example A square is a special sort of rectangle, right?
Can we substitute square for rectangle? Seems like a square is just a rectangle that has the same width as height public class Rectangle{ public double getArea{…} public void setHeight(double){…} public void setWidth(double){…} }
Now we have duplicate methods setHeight setWidth
So set them to maintain structure public class Square{ private double _width; private double _height; setHeight(double height){ _height = _width = height; } setWidth(double width){ _width = _height = width;
But now… [Fact] public void Area_calculates_properly(){ var rectangle = new Square();//substitute rectangle.setHeight(5); rectangle.setWidth(4); rectangle.getWidth().Should().Be.EqualTo(20)//boom }
Not as many things are inherited as you might think So… Not as many things are inherited as you might think
Interface Segregation Robert C. Martin
What is it? Clients should not be forced to depend upon interfaces they do not use Avoids coupling between objects that are largely unrelated Improves cohesion
Random Number Generator Example Strategy pattern – random number generation Random Number Generator Time-based RNG External Entropy RNG
Random Number Generator Example Random Number Generator Time-based RNG External Entropy RNG public interface RandomNumberGenerator{ void SetSeed(double); int NextInt(); double NextDouble(); }
Example Random Number Generator External Entropy RNG Time-based RNG public interface RandomNumberGenerator{ void SetSeed(double); int NextInt(); double NextDouble(); } Isn’t used by time-based RNG
Random Number Generator Example Random Number Generator Time-based RNG External Entropy RNG Seedable public interface RandomNumberGenerator{ int NextInt(); double NextDouble(); } public interface Seedable{ void SetSeed(double);
Dependency Inversion Robert C. Martin
Dependency Inversion High level classes should not depend on concrete implementations of low level classes Changes to implementation should be bounded inside an abstraction
Dependency Inversion High level classes should not depend on concrete implementations of low level classes Changes to implementation should be bounded inside an abstraction Frequently related to dependency injection, but doesn’t have to be (factory, service locator, plugin)
An example LoginController UserManager Login()
An example LoginController UserManager Login() LoginUser() EncryptedUser Manager
An example LoginController IUserManager Login() EncryptedUser Manager
Code public class LoginController{ public ActionResult Login(){ var userManager = new UserManager(); userManager.login(); } public class UserManager{ public bool Login(){}
Code public class LoginController{ public LoginController(IUserManager userManager) { _userManager = userManager; } public ActionResult Login(){ _userManager.login(); public interface IUserManager{ bool Login();
Code public class UserManager:IUserManager{ public bool Login(){} } public class EncryptedUserManager{
Your classes will be… Small Changed infrequently Implement multiple interfaces Testable
Criticism Places a lot of emphasis on extension over composition Class hierarchies don’t necessarily exist in business situations
These are the MeetUps you’re looking for… Testing – Nov. 26, 2014 SOLID – Feb. 26, 2015 Dependency Injection – June Source Control – Branching/Merging – July Putting It All Together – TBD
ReSharper license to the first person to tell me what DRY stands for NOW PRIZES!! ReSharper license to the first person to tell me what DRY stands for https://www.jetbrains.com/resharper/
Further reading
Further reading Open Closed Principle http://www.objectmentor.com/resources/articles/ocp.pdf 19 ½ things to make you a better OO programmer https://vimeo.com/17151526
Further reading Uncle Bob’s Article http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Thanks Dave White @agileramblings Simon Timms @stimms stimms@gmail.com TechEd 2013 11/17/2018 6:14 PM Thanks Dave White @agileramblings http://www.agileramblings.com dave@depthconsulting.ca Simon Timms @stimms http://blog.simontimms.com stimms@gmail.com © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.