• Save


Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Some Cool Design Patterns, Practices, and Principles






Total Views
Slideshare-icon Views on SlideShare
Embed Views



1 Embed 5

http://www.linkedin.com 5



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • Say more with less, shared vocabulary speeds up development and reduces chances of confusion and misunderstanding.
  • Constructor Over Injection: If the class can function without a particular dependent object, it shouldn’t demand it in the constructor.

Some Cool Design Patterns, Practices, and Principles Some Cool Design Patterns, Practices, and Principles Presentation Transcript

  • Some Cool Design Patterns, PRACTICES, AND PRINCIPLES
    Presented by Arsalan Ahmed
  • What Are Design Patterns?
    Well-understood code patterns
    Solve common problems
    Create common pattern vocabulary
    Speed up design and development
    Encourage creating design standards
  • Useful Design Principles
    Prefer Composition over Inheritance
    Program to abstractions instead of concrete implementations
    Design loosely coupled components
    Encapsulate what varies
    Hide the likely-to-change code behind an interface
  • Time-Tested Design Principles
    S – Single Responsibility Principle
    One reason to change per class
    O – Open-Closed Principle
    Classes open for extension, closed for modification
    L – Liskov Substitution Principle
    Classes can be substituted if designed to be referenced via their public contracts
    I – Interface Segregation Principle
    Interfaces should not be bloated
    D – Dependency Inversion Principle
    Classes should not be responsible for creating their dependencies
  • Anti-Patterns
    Commonly used
    Often seem harmless
    Degrade overall design
    Avoid like a plague!
  • Example Anti Patterns
    The Arrowhead
    Constructor Over-Injection
    Gold Plating
    Interface Bloat
    God Object
    Magic Literals
    Reinventing The Wheel
  • The Gang Of Four
    Authors of the canonical book Design Patterns: Elements of Reusable Object-Oriented Software
    Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
    Main theme 1: Program to an interface instead of an implementation
    Main theme 2: Favor composition over inheritance
  • GoF Design Patterns
    Creational: Abstract Factory, Builder, Factory Method, Prototype, Singleton
    Structural: Adapter, Bridge, Composite, Decorator, Façade, Flyweight, Proxy
    Behavioral: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template, Visitor
  • Enterprise Design Patterns
    Patterns found in enterprise applications
    Major proponent: Martin Fowler of Thoughtworks
    Enterprise patterns go beyond GoF patterns
    Often specific to technology stacks
  • Pattern: The Command
    Source: dofactory.com
  • What Makes It Useful?
    Repeatable pattern to execute tasks as objects
    Allows parameterizing command invokers with different commands
    Allows undo operations
    Meta-Command Pattern allows creating composite commands
    Decouples worker objects from client objects
  • Practical Uses
    Background processing agents
    Allow third-party vendors to create and distribute custom commands
    Supports queuing requests
    Facilitates logging requests
    By serializing/deserializing objects to/from log files
    Log contains history of all command objects
    Allows implementing transaction semantics
  • Command Pattern Demo
  • Pattern: The Decorator
    Source: dofactory.com
  • What Makes It Useful?
    Facilitates implementing the open-closed principle
    Allows adding new functionality without modifying existing classes
    Promotes composition over inheritance
    Promotes iterative development
  • Practical Uses
    Dynamically creating specialized objects
    Provide flexible API with object decorators
    Example uses in the .Net framework
    BufferedStream decorates MemoryStream
  • Decorator Pattern Demo
  • Before Using The Decorator
  • After Using The Decorator
  • Pattern: Lazy Load
    Avoid performing time-consuming operations unless unavoidable
    Load data from database or an external service as late as possible
    Cache fetched data for as long as feasible
    Reduce database and/or network load
  • Code Sample
    Private Shared ReadOnly Property DTSearchIndexLocation() As String
    If String.IsNullOrEmpty(_dtSearchIndexLocation) Then
    ' fetch from database and assign to _dtSearchIndexLocation
    End If
    Return _dtSearchIndexLocation
    End Get
    End Property
  • Design Patterns In .Net
    Template Method
    Intercepting Filter
    Page Controller
  • Further Study
    Writings of The Godfather of Enterprise Design Patterns a.k.a. Martin Fowler
    Head-First Design Patterns by O’Reilly
    Writings of Uncle Bob a.k.a. Robert C. Martin
    ButUncleBob.com, blog.objectmentor.com
    Presentations by Jeremy Miller