emilybache / Racing-Car-Katas

Several code katas on a racing car theme
https://youtu.be/ldthYMeXSoI
MIT License
302 stars 351 forks source link

Visibility of fields #47

Closed pfichtner closed 2 years ago

pfichtner commented 2 years ago

https://github.com/emilybache/Racing-Car-Katas/blob/1d66edf9c94f51eb4d169d3ad192a63dd88a8251/Java/TirePressureMonitoringSystem/src/main/java/tddmicroexercises/tirepressuremonitoringsystem/Alarm.java#L8

Is it intentional that the fields are not private? This makes "get it under test without changing the production code" relatively easy (which it wouldn't be otherwise)

Alarm alarm = new Alarm();
alarm.sensor = new MySensorStub();
emilybache commented 2 years ago

You make a good point. I was just looking at the other language versions and most have it private or protected. Package level privacy in Java is really quite permissive! I'd accept a pull request to make it protected, if you'd like to send one?

pfichtner commented 2 years ago

Is there anything wrong with changing it to private? Otherwise when leaving it protected, replacing the field in a inheriting Alarm class again would be to easy, wouldn't it?