We have no way of knowing. And that is the only correct answer to that particular question.
One thing people don’t understand about object orientation is that it’s not a way to apply cake recipes and everything will be beautiful and it will work wonderfully. It’s not the OOP mechanisms that make the code look good, how to apply them is what makes the code good or bad.
There is no way to tell if something is the most appropriate or not without knowing the context, without referring to a specific case. That’s why I always say this "best practice" thing doesn’t work. If it were a checklist always considering options it would be a good one, but in the way they are usually exposed and propagated they usually cause more harm than good. They do not consider context and, in general, "push" an idea that wants to "sell". And make no mistake, they’re always trying to sell something, I’m doing it now. Only you can discern what is best and know when to apply what in each case.
The question has no requirements, it doesn’t say what you need to do, so whatever you’re going to do. That’s what I say, before you know the answer you need to know the question. When the question is wrong (part of wrong premise), incomplete (does not have all the necessary data), or is irrelevant (that does not matter), the answer will never be adequate.
In abstract examples one can talk about the mechanism, but one cannot talk about its adequacy. And the question is about adequacy and not about the mechanism.
I don’t know if you need the builder, I don’t know if he’s enough. I don’t know if I should be able to access or modify each of the members by myself. And if I can, I don’t know if I shouldn’t have something else in it. I don’t know if a public field is enough, in general PHP is. I don’t know if the right one should use __get()
and __set()
language standard. I don’t know if it should be a class or a array associative, who knows with some loose functions, is sufficient.
If the code were that, I’d go the simple way array associative with a function that delivered the most formatted data. If there was a context then I could tell you how I would do. But already I say that in PHP I would still make it very simple, not create unnecessary things. I do not adopt the position cult Programming.
I think I understand what you mean, complex then.. Basically I must learn OOP but not everything you say is what it is?
– WSS
It’s really complex.
– Maniero
In my opinion __Construct and some other native OOP methods only serve to complicate, since you can opt for simpler and more practical methods.
– Skyline
And you can choose not to do OOP which also complicates. But if you are going to do OOP, they are very useful.
– Maniero