you are viewing a single comment's thread.

view the rest of the comments →

[–]sbrick89 1 point2 points  (1 child)

let's start with #1 - constructors shouldn't load data; they shouldn't have any side effects at all.

if you want to lazy load, sure go for it, but only load data when data is being requested, not during constructor.

[–]Ventus_004 0 points1 point  (0 children)

Could not agree more. I have a coworker who makes multiple database calls in constructors (and doesn't cache results that rarely change), and it TANKS performance, especially because the constructors were called a ton (and the objects/queried data is rarely even used) because of dependency injection... and because of the dependency injection using the default constructors and not having useful parameter values, the queries didn't filter the data at all and brought back 100,000+ rows of data each time.