Your SlideShare is downloading. ×
0
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
Qt Design Patterns
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

Qt Design Patterns

2,844

Published on

Design Patterns help us solve problems in tried and tested ways. …

Design Patterns help us solve problems in tried and tested ways.

Turns out they also help us understand our framework better, for framework developers also use patterns.

In these slides you'll see how Design Patterns are implemented by Qt framework, to better both understand patterns and Qt

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,844
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
50
Comments
0
Likes
1
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. C++/Qt DesignPatternsYnon Perekynon@ynonperek.comhttp://ynonperek.comSunday, May 5, 13
  • 2. Good Code Bad CodeSunday, May 5, 13
  • 3. When OOGoes WrongSunday, May 5, 13
  • 4. Java InputValidation• In the past, Java Swingprovided only JTextField forinput texts• JNumericTextField quicklyappeared by the communitySunday, May 5, 13
  • 5. Java InputValidationSunday, May 5, 13
  • 6. OO Fail• Too many classes• Hard to maintain• Frustrated DevelopersSunday, May 5, 13
  • 7. Enter Design Patterns• Reusable and tested solutions• Sustainable for the long runSunday, May 5, 13
  • 8. Enter Design Patterns• Started by ChristopherAlexander in 1977• And he was an ArchitectSunday, May 5, 13
  • 9. Example: Street Caffe“The street cafeprovides a uniquesetting, special tocities: a place wherepeople can sit lazily,legitimately, be onview, and watch theworld go by...”Sunday, May 5, 13
  • 10. Patterns Are Not• Not a detailed solution• Not a guide to help you build itSunday, May 5, 13
  • 11. Patterns Are• Describing existing and working solutions• Your job: Apply to yourworldSunday, May 5, 13
  • 12. Patterns In Software• Defined by GoF• Categorized:• Creational• Behavioral• StructuralSunday, May 5, 13
  • 13. Using Patterns• Understand• Memorize• Apply RepeatedlySunday, May 5, 13
  • 14. Patterns In Qt• Plenty !• We’ll show 2:• Strategy• ProxySunday, May 5, 13
  • 15. Strategy PatternSunday, May 5, 13
  • 16. The Problem• An input text provides different validationtechniques• Only one is used at any given timeSunday, May 5, 13
  • 17. Approach #1Sunday, May 5, 13
  • 18. Why Is It Bad• Class Explosion• Hard to reuse validation codeSunday, May 5, 13
  • 19. The Better WaySunday, May 5, 13
  • 20. Why Is It Awesome• Can reuse validators code• Reduce class explosionSunday, May 5, 13
  • 21. The Pattern• A validator encapsulates the validationalgorithm• The general pattern is called StrategySunday, May 5, 13
  • 22. Intent• Define a family of algorithms, encapsulate eachone, and make them interchangeable.Sunday, May 5, 13
  • 23. Motivation• Client code is simpler if the algorithm isexternal to it• No need to support an algorithm we don’tuse• We need to make it easy to add newalgorithmsSunday, May 5, 13
  • 24. Applicability• Configure a class with one of manybehaviors• Use different variants of an algorithm• Eliminate Switch blocksSunday, May 5, 13
  • 25. StructureSunday, May 5, 13
  • 26. Participants• Strategy• ConcreteStrategy• ContextSunday, May 5, 13
  • 27. Collaborations• Strategy + Context = Algorithm• Context forwards requests to StrategySunday, May 5, 13
  • 28. Consequences• Families of related algorithms• Eliminate switch blocks• Allow different implementations• Strategy and Context interface can getcomplicated• Increased number of objectsSunday, May 5, 13
  • 29. More Examples• Layout management• QAbstractNetworkCacheSunday, May 5, 13
  • 30. Keep In Mind• A Default Strategy will make everyonehappy• Allow clients to create their own strategiesand pass as parametersSunday, May 5, 13
  • 31. DemoSunday, May 5, 13
  • 32. Q & ASunday, May 5, 13
  • 33. Proxy PatternSunday, May 5, 13
  • 34. ______________< Lets do COW >-------------- ^__^ (oo)_______(__) )/||----w ||| ||Sunday, May 5, 13
  • 35. Example CodeQString s1 = getText();QString s2 = getText();QString s3 = s1;// "Hello World" is kept in memory only onces1.append(" And now its copied");Sunday, May 5, 13
  • 36. The Proxy Way• A QString is just a proxy to the data• Implicitly sharedSunday, May 5, 13
  • 37. class MyCow{public:MyCow &operator=(const MyCow &other){m_data = other.m_data;}void write(){m_data = new Data( m_data );m_data.write();}private:Data *m_data;};The Proxy WaySunday, May 5, 13
  • 38. Proxy Types• Virtual Proxy• Protection Proxy• Remote ProxySunday, May 5, 13
  • 39. Proxy: Pattern DetailsSunday, May 5, 13
  • 40. Intent• Provide a surrogate or placeholder for anotherobjectSunday, May 5, 13
  • 41. Motivation• Save time by lazy loading heavy resources• Easy CowsSunday, May 5, 13
  • 42. Applicability• Access remote resources• Create resources on demand• Enforce per-object access controlSunday, May 5, 13
  • 43. StructureSunday, May 5, 13
  • 44. Participants• Proxy• Subject• Real SubjectSunday, May 5, 13
  • 45. Collaborations• Proxy forwards requests to Real SubjectSunday, May 5, 13
  • 46. Consequences• Hide the fact that an object is remote• Optimize load times (virtual proxy)• Can use for Copy-On-WriteSunday, May 5, 13
  • 47. Qt Cow• Not really “By The Book”• QString has a Data struct• Does all work by itselfSunday, May 5, 13
  • 48. Qt Patterns• Patterns are part of any framework (QtIncluded)• Understanding patterns helps us betterunderstand the frameworkSunday, May 5, 13
  • 49. Thanks ForListening !Slides at:http://ynonperek.comQuestions / Comments:ynon@ynonperek.comStock Photos from:http://123rf.comSunday, May 5, 13
  • 50. Thanks For ListeningSunday, May 5, 13

×