Constructor Parameters vs Method Parameters? [closed]

It depends 🙂

Basically, object-orientation states that objects should encapsulate data and behavior. When you pass data as constructor parameters, you indicate that this is the data to encapsulate.

On the other hand, when you pass data as parameters, you indicate that this is data that somehow is less coupled to the object. Once you begin to move towards Data Context Interaction (DCI), lots of objects tend more and more to encapsulate behavior rather than data.

At the same time, the book Clean Code also guides us to limit the number of method parameters, towards the ultimate conclusion that a method with no parameters is the best design of all.

So I would tend towards encapsulating the data by passing it as constructor parameters in order to have simple APIs. It would then look much like a Command object.

Leave a Comment