|
| 1 | +--- |
| 2 | +title: "General Design Principles" |
| 3 | +teaching: 0 |
| 4 | +exercises: 0 |
| 5 | +questions: |
| 6 | +- "What are most commonly used design principles?" |
| 7 | +objectives: |
| 8 | +- "To introduce common design principles" |
| 9 | +keypoints: |
| 10 | +- " " |
| 11 | +--- |
| 12 | + |
| 13 | +# General Design Principles |
| 14 | + |
| 15 | +## Found on the web |
| 16 | + |
| 17 | +* Encapsulate what varies |
| 18 | +* Favor composition over inheritance |
| 19 | +* Program to interfaces not implementations |
| 20 | +* Loose coupling – interacting components should have minimal knowledge about each other |
| 21 | +* SOLID |
| 22 | + * Single responsibility |
| 23 | + * Class/method/function should do only one thing |
| 24 | + * Open/closed |
| 25 | + * Open for extension\, close for modification |
| 26 | + * Liskov substitution |
| 27 | + * Implementations of an interface should give same result |
| 28 | + * Interface segregation |
| 29 | + * Client should not have to use methods it does not need |
| 30 | + * Dependency inversion |
| 31 | + * High level modules should not depend on low level modules\, only |
| 32 | + on abstractions |
| 33 | + |
| 34 | +These are just some of the links that have more details on these |
| 35 | +design principles. |
| 36 | + |
| 37 | +https://www.freecodecamp.org/news/solid-design-principles-in-software-development/ |
| 38 | +https://www.bmc.com/blogs/solid-design-principles/ |
| 39 | +https://bootcamp.uxdesign.cc/software-design-principles-every-developers-should-know-23d24735518e |
| 40 | + |
| 41 | + |
| 42 | +# Designing Software – High Level Phases |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +As shown in the figure above, software design has three phases: |
| 47 | +requirements gathering, decomposition, and understanding connectivity |
| 48 | +with that decomposition. These phases come one after another, though |
| 49 | +one can iterate over them as needed. |
| 50 | + |
| 51 | +# Requirements Gathering |
| 52 | + |
| 53 | +In the requirement gathering phase the developers gather information |
| 54 | +about what is needed from the software. As an extremely simple example |
| 55 | +is writing an integer sorter. At first glance it appears that only |
| 56 | +requirement is to read in a bunch of integers, sort them in specified |
| 57 | +order, and output the sorted numbers. However a few other requirements |
| 58 | +may dictate actual implementation. For example: |
| 59 | + |
| 60 | +* How large is the dataset -- will simplest O(N<sup>2</sup>) method |
| 61 | +suffice or does one need O(NlogN) method |
| 62 | +* Is the dataset large enough that a parallel sorting algorithm needed |
| 63 | +* Is it a stand-alone code or is it going to be used in another code |
| 64 | +(in other words does it handle I/O or needs to have arguments) |
| 65 | + * If it needs I/O then what is format of input and output files |
| 66 | + * If it has arguments what should the interface look like |
| 67 | + |
| 68 | +It may seem like an obvious approach to take, but if you think a |
| 69 | +little about what is involved you will realize that failing to get |
| 70 | +these specifications will likely accrue some technical debt which will |
| 71 | +have to be paid later through modifications in the code. |
| 72 | + |
| 73 | +# Decomposition |
| 74 | + |
| 75 | +Once requirements are known one can proceed to design components of |
| 76 | +the software. In the sorting example the simplest case of small |
| 77 | +dataset to sorted through a function call will have just one |
| 78 | +components. If it is a stand-alone piece of software then it may be |
| 79 | +divided into three components, one for I/O, one for sorting, and the |
| 80 | +driver that invokes the other two components. If it is |
| 81 | +a stand-alone parallel sorter then it may either incorporate |
| 82 | +parallelization in the driver, or may add another component to handle |
| 83 | +the parallelization. |
| 84 | + |
| 85 | +# Connectivity |
| 86 | + |
| 87 | +This phase of design is devoted to understanding the interdependencies |
| 88 | +between components. In the stand-alone parallel sorting example with a |
| 89 | +separate parallelization component we infer the following |
| 90 | +connectivity: |
| 91 | + |
| 92 | +* Driver knows all other components and invokes them as needed |
| 93 | +* I/O is called by the Driver and no other component. If parallel I/O |
| 94 | + is being used then it needs to have an interface with the |
| 95 | + parallelization component |
| 96 | +* Sorter is called by the driver, but it also needs access to the |
| 97 | +parallelization component |
| 98 | +* Parallelization component is called by the driver and the sorter. It |
| 99 | +may also be called by I/O if we are using parallel I/O |
| 100 | + |
| 101 | +One immediate concern that you may have is that this approach is not |
| 102 | +compatible with agile methodology. It is not because complete design of a |
| 103 | +complex software may need several iterations over the three phases. It |
| 104 | +need not all happen before development begins. It can happen anytime |
| 105 | +during the development cycle, and in all probability some or all of |
| 106 | +the phases may need to be reconsidered as understanding grows. |
| 107 | + |
| 108 | +In the next section we will work through a real life application design. |
| 109 | + |
| 110 | + |
0 commit comments