- Mastering macOS Programming
- Stuart Grimshaw
- 421字
- 2021-07-02 22:54:26
MVC and Other Design Patterns
There are many ways to write a program. At every level, from the overarching architecture of a program's design, through the separation of functionality into distinct layers and the implementation of individual classes, right down to the ways in which functions engage with each other, there is a wide range of strategies to choose from. These are accompanied by innumerable zealots of one style to the detriment of all others, silver bullet blog posts, and the dreaded Latest Thing that allegedly only aged, bearded Fortran developers can afford to ignore.
This is made all the more exciting by the fact that there are so many right ways of performing so many programming tasks. And it's your privilege as a developer to select the best method for any given task under the given circumstances.
And so, this chapter is dedicated to covering some of the most common programming and design concepts that are potentially applicable to macOS development using Swift. Because macOS is our target platform, we should acknowledge up front that the depth of coverage - or lack of it - of any particular topic is not an indication of its importance, but much more a reflection of its relevance to programming with the Cocoa frameworks.
The material presented here is very far from complete; these are topics worthy of decades of postgrad research, and our intention here is to break the ice, so to speak, and start the process of deepening our understanding of issues above and beyond the code itself.
The aims of this chapter are as follows:
- To give you an idea of the overall landscape of relevant programming paradigms and design patterns
- To provide you with a number of concepts to be aware of while planning and writing your code
- To provide you with some pointers to further reading (sooner or later) and research
- Provide a strong rationale for the strategies followed throughout this book
It is not necessary to memorize every word of this chapter. The concepts covered here come up constantly in our discussions of programming for macOS in the rest of the book. At the moment, we're simply setting a context in which everything that comes later can be comprehended more easily, and many of the ideas here will take a little while to settle down, make sense, and finally, become part of your day-to-day programming.
The topics covered in this chapter include the following:
- The meaning of programming paradigms
- Imperative and object-oriented programming
- Declarative and functional programming
- Encapsulation and isolation