Book contents
- Frontmatter
- Contents
- List of Code examples
- Preface
- Acknowledgements
- Programming hints, condensed
- Part I TinyOS and nesC
- Part II Basic programming
- Part III Advanced programming
- 8 Advanced components
- 9 Advanced wiring
- 10 Design patterns
- 11 Concurrency
- 12 Device drivers and the hardware abstraction architecture (HAA)
- 13 Advanced application: SoundLocalizer
- Part IV Appendix and references
- References
- Index
10 - Design patterns
Published online by Cambridge University Press: 05 August 2012
- Frontmatter
- Contents
- List of Code examples
- Preface
- Acknowledgements
- Programming hints, condensed
- Part I TinyOS and nesC
- Part II Basic programming
- Part III Advanced programming
- 8 Advanced components
- 9 Advanced wiring
- 10 Design patterns
- 11 Concurrency
- 12 Device drivers and the hardware abstraction architecture (HAA)
- 13 Advanced application: SoundLocalizer
- Part IV Appendix and references
- References
- Index
Summary
To quote the Gang of Four, design patterns are “descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.” [3] In the components we've seen so far, we see several recurring patterns, such as the use of parameterized interfaces to implement services with multiple clients (VirtualizeTimerC, Section 9.1.3), or one component wrapping another (RandomC, Section 4.2). In this chapter, in the spirit of the Gang of Four's original design patterns work, we attempt to formalize a number of these patterns, based on our observations during TinyOS's development.
This chapter presents eight nesC design patterns: three behavioral (relating to component interaction): Dispatcher, Decorator, and Adapter, three structural (relating to how applications are structured): Service Instance, Placeholder, and Facade and two namespace (management of identifiers such as message types): Keyspace and Keymap. Each pattern's presentation follows the model of the Design Patterns book. Each one has an Intent, which briefly describes its purpose. A more in-depth Motivation follows, providing an example drawn from TinyOS. Applicable When provides a succinct list of conditions for use and a component diagram shows the Structure of how components in the pattern interact.1 In addition to our usual conventions for component diagrams, we attach folded sub-boxes to components to show relevant code snippets (a floating folded box represents source code in some other, unnamed, component). The diagram is followed by a Participants list explaining the role of each component. Sample Code shows an example nesC implementation, and Known Uses points to some uses of the pattern in TinyOS. Consequences describes how the pattern achieves its goals, and notes issues to consider when using it.
- Type
- Chapter
- Information
- TinyOS Programming , pp. 166 - 191Publisher: Cambridge University PressPrint publication year: 2009
- 1
- Cited by