php - Debug class as singleton? -


my question simple: should create debug class singleton?

i know the singleton pattern bad practice, debug class not take part in logic in app, , complexify entire application inject debug class every class.

my debug class contain methods such as:

debug::message(); debug::dump(); debug::spot(); // create timeline // etc 

it should noted use the debugbar package, , present in dev mode, debug class if package present, if so, pass informations it, otherwise, nothing (or maybe log important things).

ok, want do static calls avoid tossing around instance of debug class. makes sense.

and if want use static calls, alternative singleton write class consists of static properties/methods.

the decision whether go or singleton pretty simple: class have internal state and/or require constructor? example, if open log file or instantiate other objects, you’ll want singleton.

singleton frowned upon, , there are reasons this. there still situations makes sense , valid approach.

you mention want create timeline, guess need initialize timestamp. have dump method, guess want collect information dump later. these things stateful.

of course, call sort of debug::init() @ top of every public method, stupid , worse singleton.

so, in specific case, guess singleton indeed make sense.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -