-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Use functional options when:
- The behaviour needs to be tweaked
- E.g.:
DryRun,Debug,UseHttp,IgnoreChecks, etc. - E.g.: Support
reuse a cached buildas well asbuild alwaysfeatures
- E.g.:
- TIP: API needs
boolean flags&optional features - TIP: Remember functional options is often used with variadic arguments
- I.e.: There can be no args or a bunch of them & both of these should be perfectly valid
- TIP: It is wrong if clients have to remember which functional option is mandatory vs. optional
Do not use functional options when:
- Multiple behaviours are desired
- Github release vs Gitlab release
- Main actor / entity changes or requires additional entities/actors
Running on MacvsRunning on Windows
- More examples:
Save file to Databasevs.Publish file to CDNBuild using makevs.Build using make inside containerBuild inside containervs.Build inside K8s PodBuild inside Gitlab runnervs.Build inside Jenkins runner
- Use of functional options in above case leads to:
- [1] A single structure that caters to all possible requirements
- [2] Explosion in the number of functions exposed from a single package
- Most importantly the
Single Responsibility Pattern(i.e.Sin SOLID) is violated due to [1]
- Summary: Functional options is not right if it breaks any of the SOLID principles
- Remedy: Stick to
old school patterns,idiomatic&effectivepractices - Test: Keep verifying the implementations against SOLID principles
Reactions are currently unavailable