1 / 23

xkcd

xkcd.com. Applied Object-Oriented Design Principles. Jay Hill jayhill@jayhill.net @jittery codequota.com speakerrate.com/ jayhill. Objectives. touch on useful, less prominent design patterns demonstrate implementation and sample use cases leverage language/compiler features

thai
Télécharger la présentation

xkcd

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. xkcd.com

  2. Applied Object-OrientedDesign Principles Jay Hill jayhill@jayhill.net @jittery codequota.com speakerrate.com/jayhill

  3. Objectives • touch on useful, less prominent design patterns • demonstrate implementation and sample use cases • leverage language/compiler features • draw connections – SOLID & patterns

  4. A Word On Patterns • useful • elegant • extensible • capacity for evil

  5. Single Responsibility Principle (SRP) • Open-Closed Principle (OCP) • Liskov Substitution Principle (LSP) • Interface Segregation Principle (ISP) • Dependency Inversion (DI) LM G/B TFY

  6. Null Object Pattern • Specialization of Special Case Pattern • Useful when consumers of your object/API expect always to get an object

  7. Null Object Pattern • Enumerator • Factory • Fluent interface

  8. demo: null object pattern

  9. Enums Enough public enum ItStarts { OutSimply, Enough, WeJustWant, AListOf, NamedConstants, ThatAreHandy, ToCallAndUse, NotMagicNumbers, ButThen, WeWantMore, AndMoreStill }

  10. Enums Enough [Description(“Slippery Rise-over-Run”)] #dadjoke

  11. Intervention • Admit you have a problem • Step away from the enum • Embrace the power of object • Join a 12-step program

  12. 3ish-Step Enum Recovery 1. static members 2. static constructor 3… Everything else • Interface implementations • Instance members • Equality overrides • Inheritance

  13. An enum is more performant by virtue of living on the stack as a value type, rather than a reference type that gets piled on the heap • Bitmask operations (flags) are free with the purchase of any enum

  14. demo: enums enough

  15. Nested Classes • Are they necessary? • Are they useful? public class Foo { private class Bar { } }

  16. Nested Classes • Ad here to SRP while reducing “class explosion” • Control access & inhertance

  17. LSP

  18. demo: nested classes & IDisposable

  19. Composite Pattern • Intelligent multiplicity, masquerading as a single object • Relies on abstractions • Can avoid cascading refactorings / API changes • Plays nice with factories, like Decorator and Proxy Patterns

  20. Recapitulation • Pattern usage • Null Object Pattern • Nested classes • Leveraging IDisposable + using • enum abuse & how to get help • Composite Pattern

  21. Image Sources • http://blogs.msdn.com/b/expression/archive/2008/03/19/mix08-session-xaml-ready-agency-with-expression-blend.aspx • http://designinformer.com/wallpaper-week-solid/ • http://touchingspiritbearsummerreading.blogspot.com/2009/07/after-reading-july-1st.html • others… whoops

  22. Applied Object-OrientedDesign Principles Jay Hill jayhill@jayhill.net @jittery codequota.com speakerrate.com/jayhill

More Related