From design patterns to reactive programming
Even though the design pattern movement is aligned with OOP, and reactive programming is aligned towards FP, there are close similarities between them. In a previous chapter, we learned the following:
- The OOP model is good for modeling the structural aspects of a system.
- The FP model is good for modeling the behavioral aspects of a system.
To illustrate the connection between OOP and reactive programming, we will write a program that will traverse directories to enumerate files and sub-folders within a given folder.
We will create a composite structure that contains the following:
- A
FileNode
(inherits fromEntryNode
) that models file information - A
DirectoryNode
(inherits fromEntryNode
) that models folder information
After defining the preceding composites, we will define visitors for the following:
- Printing filenames and folder names
- Converting a composite hierarchy to a list of filenames
Without further ado, let's get into the meat of the stuff. Take...