magic numbers - SOLID principles, and hard code configuration inside a class -


i have noticed in lot of code lately people put hard coded configuration (like port numbers, etc.) values deep inside of classes/methods, making difficult find, , not configurable.

is violation of solid principles? if not, there "principle" can cite team members why it's not idea? don't want "it's bad because don't it" having trouble thinking of argument.

a argument against hardcoding tcp port number in class 'context independence' violation. goos, emphasis:

context independence

... "context independence" rule helps decide whether object hides or hides wrong information. system easier change if objects context-independent; is, if each object has no built-in knowledge system in executes. allows take units of behavior (objects) , apply them in new situations. context-independent, whatever object needs know larger environment it’s running in must passed in.

in specific case of context independence call 'environment independence'. in other words class hardcoded port number has inappropriate dependency on runtime os environment, stating 'i know port 7778 available' wrong.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -