oezg / minesweeper-kt

Minesweeper game
0 stars 0 forks source link

Refactor Cell class #1

Closed oscarnava closed 4 months ago

oscarnava commented 4 months ago

I've refactored the Cell class. Among the changes: You had the isMarked and isExplored, which were both var properties open to change from external code. That beats the encapsulation principle.

Let me know what you think.

oezg commented 4 months ago

After the commitment the tests failed, I will rewrite it.

oezg commented 4 months ago

In C# there is a difference between field and property. Fields are usually private and Properties are usually public. cellMarked must be a field here it is a property.

oscarnava commented 4 months ago

In C# there is a difference between field and property.

I've always wanted to explore C#; maybe you can be my mentor. 😉

Fields are usually private and Properties are usually public. cellMarked must be a field here it is a property.

The main issue is having an internal member (mainly a var member) accessible from outside the class. This would allow anyone to alter the internal state of the instance without its knowledge. This is part of the encapsulation principle and we must avoid it.