|
| 1 | +# Design patterns |
| 2 | + |
| 3 | +* there are 23 patterns in the book |
| 4 | +* the patterns include solutions which have developed or evolved over time |
| 5 | + * => they are not designs people initially tend to generate |
| 6 | + * they are solutions people have evolved into |
| 7 | + * ASIDE: it is no surprise that they often feel like "overkill" given this history |
| 8 | +* the patterns represent "common ways that objects can collobarate" |
| 9 | +* the goal of the patterns is to make your code more **reusable** |
| 10 | + * => my guess is that design pattern knowledge is most applicable during |
| 11 | + the "refactor" phase where you have a solution and are now trying to find a |
| 12 | + code arrangement to make that solution optimal. |
| 13 | +* design patterns are a bunch of solutions with known trade-offs |
| 14 | +* the patterns are |
| 15 | + > a record of experience in designing OO software |
| 16 | +* they are intended to give you a "leg up" when designing software |
| 17 | +* design areas not in the book |
| 18 | + * concurrency |
| 19 | + * any application domain specific patterns e.g. web, game, databases |
| 20 | + * real time programming |
| 21 | + * UI design |
| 22 | + * device drivers |
| 23 | +* the patterns in the book are all at a paricular level |
| 24 | + * not as low-level building blocks like linked-lists, hash tables etc. |
| 25 | + * not as high-level as an entire DSL for some application area |
| 26 | + * description of objects and classes designed to solve a general design problem in a particular context |
| 27 | +* code examples are in C++ and Smalltalk |
| 28 | + * the patterns are influenced by what can be done **easily** in those languages |
| 29 | + * e.g. if they used C they might have added patterns on "inheritance", "encapsulation", |
| 30 | + |
| 31 | +Pros/cons of the patterns (from my POV) |
| 32 | + |
| 33 | +* ++ if other devs on team are familiar with them then you can communicate architecture very quickly |
| 34 | +* ?? if other devs on team are not familiar with them? |
| 35 | + |
| 36 | +The book has 2 parts |
| 37 | + |
| 38 | +1. Chapters 1 & 2: describe what patterns are, how to use them |
| 39 | +2. Chapters 3 - 5: the catalog of patterns, divided |
| 40 | + * Purpose (three types) |
| 41 | + * creational |
| 42 | + * deals with how objects are created |
| 43 | + * two subtypes |
| 44 | + * Class |
| 45 | + * defers some part of object creation to subclasses |
| 46 | + * Object |
| 47 | + * defers some part of object creation another object |
| 48 | + * structual |
| 49 | + * deals with the composition of classes and objects |
| 50 | + * two subtypes |
| 51 | + * Class |
| 52 | + * use inheritance to compose classes |
| 53 | + * Object |
| 54 | + * describe ways to assemble objects |
| 55 | + * behavioral |
| 56 | + * the way objects interact and distribute responsibility |
| 57 | + * two subtypes |
| 58 | + * Class |
| 59 | + * use inheritance to describe algorithms and flow of control |
| 60 | + * Object |
| 61 | + * describe how a group of objects can cooperate to perform a task that they could not do individually |
| 62 | + * Scope |
| 63 | + * Class |
| 64 | + * static (fixed at compile time) |
| 65 | + * Object |
| 66 | + * dynamic (can be changed at runtime) |
| 67 | + |
| 68 | +Structure of a pattern |
| 69 | + |
| 70 | +* name |
| 71 | + * allows team to discuss the pattern |
| 72 | +* problem |
| 73 | + * description of when to use the pattern |
| 74 | + * sometimes a set of criteria that must be there before you should use it |
| 75 | +* solution |
| 76 | + * describes a general arrangement of classes that will solve the problem |
| 77 | + * describes their |
| 78 | + 1. relationships |
| 79 | + 1. responsibilitie |
| 80 | + 1. collaborations |
| 81 | +* consequences |
| 82 | + * pros/cons of the solution |
| 83 | + * the trade-offs of the solution |
| 84 | + |
| 85 | + |
| 86 | +Strategy pattern example |
| 87 | + |
| 88 | +* an object that represents an algorithm |
| 89 | +* useful when |
| 90 | + * the algorithm has complex data structures you awnt to hide |
| 91 | + * you want to replace the algorithm either statically or dynamically |
| 92 | + * there are a lot of variants of the algorithm |
| 93 | + |
| 94 | + |
| 95 | +They make an analogy to a playwrites who often re-use stories that have the same structure. |
| 96 | + |
| 97 | +They mention a number of times that the objects in the pattersn are never found |
| 98 | +in the initial stages of design - they emerge when we are trying to make the |
| 99 | +design more flexible or reusable. |
| 100 | + |
| 101 | +Design patterns can be considered "techniques for making my existing design |
| 102 | +more flexible and reusable". They are not "starting points for my design". |
| 103 | + |
| 104 | + |
| 105 | +* Each operation defined by an object has a signature |
| 106 | + * signature = operation name, the objects argument it takes as arguments and its return type |
| 107 | +* A set of sigatures is an _Interface_. |
| 108 | +* A _Type_ is a name used to denote a particular _Interface_. |
| 109 | +* An object can have many types |
| 110 | +* A type can be implemented by many different objects |
| 111 | +* Interfaces can contain other interfaces as subsets |
| 112 | + * type C is a _subtype_ of P if the interface of C fully contains the interface of P. type P is the supertype of C |
| 113 | + * We say that type C "inherits" from type P |
| 114 | +* Objects are known only through their interfaces |
| 115 | +* An interface says nothing about implementation |
| 116 | + |
| 117 | +## Chapter 2: Case study - Lexi |
0 commit comments