DEV Community

Discussion on: Encapsulate state and expose behavior when writing object-oriented code

Collapse
telexen profile image
Jake C

You could always use the intent of the feature, and make the auto-property setter private, then implement your domain use case mutator function to encapsulate logic separately.

This would be preferable to writing lots of useless code just because you're used to doing it in a language that refused to come up with a better way.

Collapse
scottshipp profile image
scottshipp Author

Help us understand the motivation for a private setter. Why not provide only a getter and not have a setter at all?