Class organization

Asked

Viewed 124 times

2

I need to create a system of posts.

I’m having a hard time studying class and I’m wondering which of the two ways to use it:

class publicarPost {}
class excluirPost {}
class curtir {}

or

class Post {
 function publicarPost(){}
 function excluirPost(){}
 function curtir(){}
}

Or some form with the most beautiful code.

1 answer

2


One thing that many don’t understand about object orientation is that the paradigm is about organizing the code for meet requirements.

As it does not have the requirements in the question we have no way to say what is right. Following cake recipe and always making equal is not object orientation. In fact if cake recipes can be applied so simply probably this code should not be being written.

Of course, looking at the two examples, it is not difficult to say that the first is probably not necessary, but I cannot say. To tell the truth in PHP much of what is done in OOP is not necessary, after all are only scripts. The example of the other answer is probably not necessary to be so sophisticated.

But there are cases where you need different strategies of publishing, deletion, tanning and other actions for the same type, but in different objects. In some cases an inheritance can be a good one, in others the composition can be better and then the first example makes sense to use together with the second. But this is probably something more advanced, and again, probably an architecture not so necessary for scripts.

I always recommend to beginners starting from the beginning, OOP should not be a priority. Nobody starts a house by finishing, except in our business, so beginners bricklayers usually earn more than "experienced programmers".

  • Because it is "scripts only", by a large majority, We use OO more for code organization than need ? A more particular reason than functional ? (Except, really, the cases that need to work with dozens of equal information, where OO becomes essential) I always see your comments about OO, and it seems a vision well beyond what is usually found, where OO is used without need... I would very much like to understand this your vision by the experience you have, because it would certainly be useful for all of us !

  • 1

    @RBZ actually don’t know why they use OOP in scripts. The script is your organization. Ephemeral codes don’t need that much organization. In fact I think there’s almost no vision about O out there. There are some rare people who know a lot (not my case), there are very respected people who do not know as much as people think, their ideas n]ao make sense, but as others do not know anything, they think it does. I’m in these last months/years trying to form a more solid position and maybe even do something bigger on the subject. What I guarantee you is that OOP is used more than it should...

  • 1

    ...and most of them either know little about it, or know things very wrong (it was my case not long ago, even using it for 30 years), or even know what OOP means, they just want to do what everyone says is good. If you search my answers (https://answall.com/search?tab=votes&q=user%3a101%20%5borienta%C3%A7%C3%a3o-a-objetos%5d).

  • 1

    If you think nothing answers what you want to know, ask a question, very carefully, because it has a great chance to be broad. Inform her that you want help to improve it and not to let it fall into broad, ask for help in chat. See https://answall.com/a/277179/101, https://answall.com/a/104346/101, https://answall.com/q/88546/101, https://answall.com/a/108227/101, https://pt.overfstacklowcom/q/108047/101, https:///pt.stacklowoverf.com/q/141624/101, https://answall.com/q/14839/101

  • I will read for sure ! Being in the area of programming more for a hobby than anything else, I do a lot of research and in them one really sees several forms of use. Now in this time participating in Sopt seeing his sayings having his 30 years of experience (still maintaining humility in saying that do not know much rs) is something that caught a lot of attention and I will really be waiting for your position on this ! And congratulations on sharing !

  • 1

    I have 35 in IT, 30 in OOP (it’s almost 30). Almost everything that teaches OO is wrong, weak, incomplete, dubious, contradictory and I was slow to notice. I had several phases of loving and hating OOP, now I’m in the good phase learning how the paradigm really is and can be useful, on the way to eliminating my https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect (in the subject) and https://en.wikipedia.org/wiki/Impostor_syndrome (which I don’t think I’ve ever had strong). DK is a disgrace because it is very easy to fall into it and very difficult to realize that it has fallen, so very hard to get out (almost leads to depression:)

  • "ignorance generates confidence more often than knowledge" sensational! I will read everything in time, and whatever I can put as relevant and direct doubt, I will post !

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.