DEV Community

Discussion on: How I finally understood what a class is

Collapse
 
delbetu profile image
M Bellucci

Nice post!
From my point of view, the main concern of classes is joining behavior and data into an encapsulated piece of code.

This split the code into cohesive pieces and decreases coupling. Two good properties of maintainable code.

The caller doesn't know how the behavior is implemented it only cares about what the method does.

Creating a class as a bag of data and expose data through getters and setters is not object-oriented since it delegates the manipulation of the data to the caller. That is procedural code using classes.

My suggestion for making your final example a little more OOP is:
MoveSystem.out.println from Person class to caller class (Main).
Remove all getters from Person class. (Nobody uses them and nobody should)
Implement to_string method instead of printInfo