Your SlideShare is downloading. ×
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Omg! Patterns <decorator> by Max Titov
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Omg! Patterns <decorator> by Max Titov

238

Published on

Learn Design Patterns fun by code.

Learn Design Patterns fun by code.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
238
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. OMG! Patterns.Decorator By Max Titov maxtitov.me Ninja Software Operations
  • 2. OMG! Patterns?▶ About mostly used patterns▶ Examples of usage in real life▶ Learning by code examples▶ Learning new language
  • 3. ExampleBeauty salon. Salon businessSalon provides following services: ▶ Haircut ▶ Coloring ▶ Styling
  • 4. The Objective▶ Salon going to add list of new services▶ Salon want to have different combinations of services in their pricelist▶ Salon want’s to expand for new market and provide services for males
  • 5. System Overviewclass Salon{ string HaircutDescription(); string StylingDescription(); string ColoringDescription();}
  • 6. Don’t you feel like? WHY?
  • 7. Identifying the problems▶ There is only one thing wrong with this approach: everything. ▶ God class. Single responsibility principle? Never heard about… ▶ Code duplication ▶ Hard to test ▶ #@#$&%%!!!
  • 8. Lets do a bit of refactoring▶ Identify common interface (if any)▶ Apply single responsibility principle▶ Use of old good inheritance
  • 9. System Overviewinterface ISalonService{ string getDescription();}
  • 10. System Overviewclass Haircut: ISalonService{ string getDescription() { return ‘Haircut’; }}
  • 11. System Overview
  • 12. Muuuuuch better!
  • 13. Adding new functionality
  • 14. Requirements updateClient: Hey, we want to add twoother services and remove one.That wouldn’t take much timeright?
  • 15. Requirements update F@#kClient: Right?
  • 16. Identifying the problems▶ Requires new class for each combination of services▶ Hard to extend and maintain
  • 17. Decorator▶ The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality
  • 18. Decorator UML
  • 19. Abstract Decoratorclass abstract SalonServiceDecorator:ISalonService{ SalonServiceDecorator (ISalonService service); string getDescription();}
  • 20. Concrete Decoratorclass HaircutDecorator{ HaircutDecorator (ISalonService service); string getDescription();}
  • 21. Use of DecoratorssalonService = new SalonService();salonService = newHaircutDecorator(salonService)salonService = newStylingDecorator(salonService)salonService.getDescription()Output:> Salon service: Haircut, Styling
  • 22. System Overview
  • 23. Success!
  • 24. Code Time!
  • 25. Where Used▶ GUI Frameworks BaseElement ScrollbarBehavior(BaseElement) ShadowBehavior(BaseElement)▶ Streams FileStream GZipStream(ByteStream)
  • 26. Pros and ConsPros:+ The cure for ugly code+ Composition over inheritance (Adds flexibility)+ Add behavior at runtime without class modification+ Behavior can be reusedCons:– Too many small classes– Could be not obvious for other developers(example: Java streams)
  • 27. Books▶ Head First Design PatternsBy Eric Freeman▶Design Patterns : Elements ofReusable Object-Oriented SoftwareBy (GoF) Gamma, Helm, Johnson, Vlissides▶ Search Google for: Design patterns
  • 28. What next?More patterns! 
  • 29. Questions? OMG! Patterns. Decorator By Max TitovGet examples: www.maxtitov.me https://github.com/eolexeGet in touch: eolexe@gmail.com Twitter: eolexe

×