Why are Designers Evil?

I remember reading an article about how designers are evil (but they can't fit it). The author mentioned that constructors are a special case of methods; but have restrictions (for example, they cannot have a return value).

Are constructors evil? Is it better to have constructors and instead rely on a type method as Initializewell as default values ​​for member variables?

(Your answer may be specific to C # or Java if you must specify a language.)

+3
source share
12 answers

. , , -:) , . . , - !

, , , , factory, Initialize. : .

, -

DatabaseConnection dc = new OracleDatabaseConnection(connectionString);
dc.query("...");

, . , unit test , ? , Mysql, ?

:

DatabaseConnection dc = DatabaseConnectionFactory.get(connectionString);
dc.query("...");

, , , DatabaseConnectionFactory.get(), . .

: "", extends , one.

+5

. , , Inversion of Control, . , , .

+3

? .

, "", . , .

, , ? , , , .

+2

. ( ) .

, .

.

+1

, ( , Java) Factory (, , ).

Java, 1: Factory

factory , , , . , , , Factory .

...

factory , , , theyre. (. 15) - theyre , .

...

factory , , , .

...

factory , . , , , theyre . , :

Map<String, List<String>> m =
new HashMap<String, List<String>>();

...

Factory - , .

...

Factory , .

+1

, .

, , . Initialize, . , .

0

. , , , .

0
. - , . , , .NET, #, , - .
0

OO. , , , Factory ctors . / , - , , , .

( - , )

0

Java #, javascript. Javascript . Javascript- .

javascript : JavaScript "" , ?

0

- , " ", YouTube. , , " ", .

The point of this argument, at least as I understand it, was that constructors that accept everything that the object wants, prompt you to apply the correctness with the help of the constructor, instead of ensuring the correctness with the help of tests. Designers tend to swell to do just that, so if that bothers you, you might consider this an evil bar in the design concept. In a conversation, he says that he prefers to require the object to "have" another object when he needs to do something, rather than demand it when building.

0
source

All Articles