gocom / danpu

Optimized MySQL dump library written in PHP
MIT License
62 stars 15 forks source link

Avoid heavy work in constructor #27

Closed apapsch closed 2 years ago

apapsch commented 4 years ago

Creating an object does not carry the expectation that something is done behind the scenes. That's not an absolute, though side effects should be kept minimal. Here however, creating the object carries huge side effects, creating a potentially big file or overwriting a database.

Also, you don't necessarily want to do the task at hand right at construction time. Consider dependency injection: component A would get a danpu dumper injected via As constructor. Right now, that isn't possible (or rather it's possible but undesirable, because of the side effect).

Since new Export($foo) is the only public interface of Export it is equivalent to a function call, e.g. danpu_export($foo). Another way that stays in object oriented confines is moving the side effects to a dedicated public method.

Are you open to moving the side effects? It would require new major version, because it would break compatibility.