php - How to condition behavior in a unit to global config value -


if want write s.o.l.i.d. code what's best way condition behavior inside loosely coupled , testable unit global configuration value?

is better inject sort of object containing information or reference global static/singleton?

i'm working php guess question language agnostic.

thanks in advance.

if have 2 different behaviors depending on global state / configuration, refactor out strategy (strategy pattern) , inject strategy.

it job of main inject correct strategy depending of configuration.

if strategy depends on changing configuration i.e. configuration changes @ runtime, strategy should wrapped in provider/supplier. (probably not case php)

an alternativ have generic feature-toggle type injected. toggle can setup main return true or false. toggle object can have more complex logic simple boolean, depends on usecase.

but don't alternative, because simpler class didn't know 2 different behaviors.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -