foundations of programming

Download Foundations of programming

Post on 05-Jul-2015

126 views

Category:

Education

2 download

Embed Size (px)

DESCRIPTION

Basics of programming methodologies.

TRANSCRIPT

  • 1. Foundations of Programming Building Better Software By Karl Seguin WWW.CODEBETTER.COM

2. Foundations of Programming Copyright Karl Seguin www.codebetter.com 2Foundations of Programming This page wasintentionally left blank 3. Foundations of Programming Copyright Karl Seguin www.codebetter.com 3Foundations of Programming License The Foundations of Programming bookis licensed under the Attribution-NonCommercial-Share-Alike 3.0 Unported license. You are basically free to copy, distribute and display the book. However, I ask that you always attribute the book to me, Karl Seguin, do not use it for commercial purposes and share any alterations you make under the same license. You can see the full text of the license at: http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode Downloadable Learning Application Reading about code is a good way to learn, but if you're anything like me, nothing beats a real application. That's why I created the Canvas Learning Application - a simple (yet complete) ASP.NET MVC website whichleverages many of the ideas and tools covered in this book. The application is a Visual Studio 2008 solution with helpful inline documentation meant to help you bridge the gap between theory and practice. The Canvas Application and this book are prettyindependent, so you can approach this journey however you prefer. http://codebetter.com/blogs/karlseguin/archive/2009/05/25/revisiting-codebetter-canvas.aspx Acknowledgement There are countless of people who deserve thanks. This book is but a small contribution to the incalculable time donated and knowledge shared by the software community at large. Without the quality books, forums, newsgroup posts, blogs,libraries and open source projects, I would still be trying to figure outwhy my ASP script was timing-outwhile looping through a recordset (stupid MoveNext). It's no surprise that the software community hasleveraged the openness of the internet more than any other professionin order to advance our cause. What is surprising is how the phenomenon appears to have gone unnoticed. Good! Of course, there is one special person without whom this couldn't have happened. To Wendy, People call me luckyfor being with someone as beautiful andintelligent as you. They don't know the half of it. You are not only beautiful and intelligent, but you let me spend far too much time on my computer, either working, learning,writing or playing. You're also more than happy to read over my stuff or listen to me blab on about nonsense. I don't appreciate you nearly as much as I should. 4. Foundations of Programming Copyright Karl Seguin www.codebetter.com 4Foundations of Programming Table of Contents About the Author...............................................................................................................................6 ALT.NET.............................................................................................................................................7 Goals..............................................................................................................................................8 Simplicity........................................................................................................................................8 YAGNI.............................................................................................................................................8 Last Responsible Moment................................................................................................................9 DRY................................................................................................................................................9 Explicitness and Cohesion................................................................................................................9 Coupling.........................................................................................................................................9 Unit Tests and Continuous Integration.............................................................................................9 In This Chapter..............................................................................................................................10 Domain Driven Design.......................................................................................................................11 Domain/Data Driven Design...........................................................................................................11 Users, Clients and Stakeholders .....................................................................................................12 The Domain Object.......................................................................................................................13 UI.................................................................................................................................................15 Tricks and Tips ..............................................................................................................................16 Factory Pattern.........................................................................................................................16 Access Modifiers.......................................................................................................................17 Interfaces .................................................................................................................................17 Information Hiding and Encapsulation........................................................................................18 In This Chapter..............................................................................................................................19 Persistence.......................................................................................................................................20 The Gap........................................................................................................................................20 DataMapper.................................................................................................................................20 We have a problem...................................................................................................................23 Limitations................................................................................................................................24 In This Chapter..............................................................................................................................25 Dependency Injection.......................................................................................................................26 Sneak Peak at Unit Testing.............................................................................................................27 Dont avoid Coupling like the Plague ..............................................................................................28 Dependency Injection....................................................................................................................28 Constructor Injection.................................................................................................................28 Frameworks..............................................................................................................................30 A Final Improvement.................................................................................................................32 In This Chapter..............................................................................................................................33 Unit Testing......................................................................................................................................34 Why Wasn't I Unit Testing 3 Years Ago?..........................................................................................35 The Tools......................................................................................................................................36 nUnit........................................................................................................................................36 5. Foundations of Programming Copyright Karl Seguin www.codebetter.com 5Foundations of Programming What is a Unit Test........................................................................................................................38 Mocking.......................................................................................................................................38 More on nUnit and RhinoMocks.....................................................................................................41 UI and Database Testing................................................................................................................42 In This Chapter..............................................................................................................................42 Object Relational Mappers................................................................................................................43 Infamous Inline SQL vs. Stored Procedure Debate ...........................................................................43 NHibernate...................................................................................................................................46 Configuration............................................................................................................................46 Relationships............................................................................................................................49 Querying..............................................................................................................................

Recommended

View more >