Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

5 Classic Patterns In Everyday Code


Published on

Patterns are an important tool to use as architects and developers. They provide a common vocabulary for us to design with, as well as a common approach to a common problem. Come learn about the five most useful patterns, and how to use them in your everyday code.

  • Be the first to comment

  • Be the first to like this

5 Classic Patterns In Everyday Code

  1. 1. @mikewo on Twitter Strategic Data Systems Centerville, OH 5 Classic Patterns In Everyday Code Presented by: ArcTrax
  2. 2. What are Patterns?
  3. 3. Now for something COMPLETELY different!
  4. 4. Design Principles
  5. 5. S ingle Responsibility Principle O pen / Close Principle L iskov Substitution Principle I nterface Segregation Principle D ependency Inversion Principle
  6. 6. Now back to your regularly scheduled presentation.
  7. 7. Types of Patterns Creational Structural Behavioral
  8. 8. Adapter Pattern
  9. 9. Adapter Pattern Client IHuman .Speak() HumanWookieAdapter .Speak() Wookie .Growl()
  10. 10. Adapter Pattern
  11. 11. Decorator Pattern
  12. 12. Decorator Pattern IceCreamIngredient .Cost public override decimal Cost() { return _internalIngredient.Cost() + .50M; } = $3.50 .Cost Vanilla Chocolate Bananas Ice Fudge .50 ¢ Cream .50 ¢
  13. 13. Decorator Pattern
  14. 14. Decorator Pattern What are some downsides with this pattern?
  15. 15. Factory Patterns
  16. 16. Simple Factory Pattern Laptop laptop; Public class LaptopFactory { switch (brand)BuildLaptop(string brand) { public Laptop { Laptop laptop; case “dell”: switch (brand) { case “dell”: laptop = new DellLaptop(); break; new DellLaptop(); return case “trashiba”: case return new ToshibaLaptop(); “trashiba”: laptop = new ToshibaLaptop(); }}} break; } LaptopFactory laptopFactory = new LaptopFactory(); Laptop laptop = laptopFactory.BuildLaptop(brand); laptop.BlueScreen(); Laptop.BlueScreen();
  17. 17. Factory Method Pattern Shipyard .CreateShip() CorellianShipyard UsNavyShipyard
  18. 18. Okay, so what what’s the difference between the simple factory and an instance of one of the derived factory classes? The both seem to do the same thing.
  19. 19. Abstract Factory Pattern .CreateHero() .CreateVillian() Universe .CreateCity() DcUniverse MarvelUniverse Batman Wolverine Joker Magneto Gotham New York
  20. 20. Factory Patterns
  21. 21. Command Pattern
  22. 22. Should it matter?
  23. 23. Command Pattern Remote Command OffCommand .Execute() GarageDoorOpenCommand .Execute() GarageDoor .Open() .Close()
  24. 24. Command Pattern
  25. 25. Remember Design Patterns provide general, reusable solutions to a commonly occurring problem in software design
  26. 26. Strategic Data Systems Centerville, OH @mikewo on Twitter ArcTrax
  27. 27. Resources Presentation Materials Pattern Resource – Do Factory Patterns in Enterprise Software (Martin Fowler) Books: Design Patterns (Gang of Four book) Head First Design Patterns by Freeman & Freeman Refactoring to Patterns by Kerievsky More Resources can be found in the presentation materials.