- Learning Functional Programming in Go
- Lex Sheehan
- 172字
- 2021-07-02 23:13:47
Open / close principle in functional programming
Similar to our preceding Go example where we added a new method (PrintInfo) to our base type (Car), pure functional programming languages also add new functions over existing data types without having to recompile existing code and while retaining static type safety.
The expression problem also known as the extensibility problem addresses a software language's ability to add new methods and types to a program in a type safe manner. For details, see Feature Oriented Software Development (FOSD) Program Cubes where a base program (in a family of related programs called a software product line) (http://softwareproductlines.com/) is incrementally augmented with features to produce a complex program.
The following diagram shows how programs can be built by composing models from features and then transforming those models into executables:
![](https://epubservercos.yuewen.com/6176FA/19470400908922906/epubprivate/OEBPS/Images/Chapter_311.jpg?sign=1739352937-Xt1x7YdKDrbG7bfUQqT0JvQR0X3yTPkP-0-a09a5bccbfc79df004b6ca9785671377)
The FOSD methodology advocates that complex systems can be built by adding features incrementally where the domain models are functions and constants and the programs, which are represented as expressions, can be generated to perform specific tasks.