iluwatar / iluwatar/java-design-patterns
Functional core, imperative shell pattern
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 94.7k
- Forks
- 27.4k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 10
Description
Description
The Functional Core Imperative Shell (FCIS) design pattern aims to segregate the purely functional part of the code (Functional Core) from the side-effect-laden part (Imperative Shell). This separation enhances testability, maintainability, and robustness by isolating side effects and minimizing their scope.
Main Elements of the Pattern:
-
Functional Core:
- Pure functions without side effects.
- Deterministic outputs based on inputs.
- Contains the business logic of the application.
- Facilitates easy unit testing.
-
Imperative Shell:
- Encapsulates side effects such as I/O operations, database access, and API calls.
- Interfaces with the outside world.
- Manages state changes and interactions.
- Bridges the Functional Core with the real-world environment.
Implementation Steps:
- Identify and extract the business logic into pure functions.
- Encapsulate side-effect operations within dedicated modules.
- Define clear interfaces between the Functional Core and Imperative Shell.
- Write unit tests for the Functional Core functions.
- Ensure integration tests cover interactions within the Imperative Shell.
References
- Functional Core, Imperative Shell - Gary Bernhardt
- Building Modern Architectures: Functional Core, Imperative Shell - Albert Llousas
- Functional Core Imperative Shell - Kenneth Lange
- A Look at the Functional Core and Imperative Shell Pattern - SSENSE Tech
Acceptance Criteria
- The project codebase should have a clear separation between the Functional Core and the Imperative Shell.
- All business logic should reside in pure functions within the Functional Core, with appropriate unit tests.
- All side-effect operations should be encapsulated in the Imperative Shell, with integration tests to ensure correct interactions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. First inspect the repository's existing pattern structure and testing conventions; done would require a clearly separated functional core and imperative shell, with unit tests for pure logic and integration tests for side effects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100