I am wondering what visibility would give best practises on using data mapping pattern?
private/public/protected
When protected I would need to use the getters() in my save() method on the mapper class.
If private and public I would be able to do $user->id; in the mapper class. What does make most sense?
In my opinion and I often use it this way, properties are protected and my class uses magic methods for getters and setters. The way I do it you are able to do both. The best thing I like about using
setter-methods is using fluent interfaces.Using fluent interfaces looks like this:
Some thoughts on the single possibilities:
Private
Using private properties prevents me from extending my model classes and reusing some functionality.
Public
There will be no way in to intercept changes to the variables. Sometimes it is needed to do something on setting.
Protected
The best way for me. The properties are not publicly changeable and I force other developers to write getters and setters for their properties which have additional functionality. Also in my opinion this way you prevent others from making mistakes in misusing your model class.