Organization of classes

2

I need to create a posts system.

I'm having trouble studying class and I'm not sure which one to use:

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

or

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

Or some way with the most beautiful code.

    
asked by anonymous 25.03.2018 / 07:27

1 answer

2

One thing that many people do not understand about object orientation is that the paradigm is about organizing code to meet requirements .

As you do not have the requirements in the question we can not say what is right. Following cake recipe and always doing the same is not object-oriented. In fact if cake recipes can be applied so simply this code should probably not be written.

Of course seeing the two examples is not difficult to say that the first is probably not necessary, but I can not say. To speak the truth in PHP much of what is done in OOP is not necessary, after all they are just scripts . The example of the other answer probably does not need to be so sophisticated.

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

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

    
25.03.2018 / 14:45