Showing posts with label mutators. Show all posts
Showing posts with label mutators. Show all posts

Wednesday, February 24, 2016

Method’s name change a lot

A few days ago I tried to help you with making a decision when you should use constructor and when setter.
In one of the paragraph I wrote:
I don’t like setters. Why? Because those methods in some way break encapsulation.
After sharing this post there were developers that were arguing that setters can be useful.

What can I say?

Sunday, February 21, 2016

Constructor or setter?

It goes without saying that every object needs to be created before it can be used. It does not matter whether we are talking about a domain, frameworks, libraries or any other type of the classes. When your code is an Object-Oriented, those classes are only definitions of the objects. You cannot use objects before they are created.

When we are talking about object’s initialization, we often need to think about dependencies. How will you inject them? Will you use the constructor or setter?