M
M
Max Ba2016-03-21 12:18:12
PHP
Max Ba, 2016-03-21 12:18:12

What for in the given example a class?

Hello guys. The question is a little philosophical, but very important for me. There was an argument with the boss.
I write websites in modules/blocks, each block is a function (header, content, footer, sidebar, css and js link modules, link form module, news module, etc.).
Index.php is called, all function files are connected, content is formed and embedded in the html template. Some functions receive variables, some do not, they are static. The boss tells me to wrap all my functions in classes. Asks to create instead of 7 functions - 7 classes. He says get used to the classes, but I don’t find much use for them in this case. How relevant is his request and why complicate the already working style of programming? My functions still do not overlap with the names of others, because they have a unique prefix, they are easily expanded by adding input variables. The only thing is that they work on a top-down basis. Sometimes you want to declare a variable in the footer and pass it to the header, but this is very rare (here I think the class would help)
It was the same with a separate module, he asked me to create a calculator for the site, it's complicated. I did it, wrapped it in one function and told him that the recure_once('modul_calc/calc.php') module is called and the function declaration in the right place on the site echo calc();, just two lines. And he's better class again. What's bad? Or is my style really not ice?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
T
trevoga_su, 2016-03-21
@trevoga_su

He says get used to the classes, but I don’t find much use for them in this case.
Certainly. Because you don’t know what they are for, you still don’t know how to think in terms of objects, and your boss is still mostly right. OOP needs to be understood and known. Read the book "grady butch object-oriented analysis and design download pdf"
Asks to create instead of 7 functions - 7 classes.
maybe 7 methods? Are all the functions so different purposes?
OOP is not just wrapping a function in a class, it is a different way of thinking, a different approach, and absolutely true and unique in programming, because everything that surrounds us - the office, your boss, the city, the universe - everything is built on an object-oriented principle.
My functions still do not intersect with the names of others, as they have a unique prefix
This is your unique prefix - this is an attempt to go towards the OOP. It starts to dawn on you, but without reading the theory it may not come soon.
why complicate
I bet your code is already complicated, even without classes.

K
kstyle, 2016-03-21
@kstyle

write a function that takes a php code file and converts all individual functions into classes and vice versa. but in general, if the boss’s argument is that you learn new things, then I agree with him

L
Lander, 2016-03-21
@usdglander

I also didn’t understand why classes and OOP were needed before, if everything works like that. Attempts to delve into the topic from articles cited on the Internet (explanations on some chairs, tables, people, students, etc.) did not give any result.
Then I just tried to write something using OOP. Something small ... Superficially mastered inheritance, constructors, static methods, etc. When writing, I thought little about the result and was surprised when everything worked the first time as it should! Before that, it took a long time to catch logical errors and debug them.
Then, by the live code of other people, I understood how to write OOP. I began to develop this object understanding in myself and noticed that in reality the code contains many times fewer errors, inaccuracies, and if something goes wrong, then I roughly understand where the error occurred.
So just start using OOP and you will understand why you need it, but first, you have to force yourself;)

J
jaxel, 2016-03-21
@jaxel

No one has been using functions and connecting modules through receive_once for a long time. Even if you wrap your functions in a class, it will have nothing to do with OOP. And the way you write, and what the boss offers you is bydlokod.
You should try one of the modern MVC frameworks - symfony 3, yii 2 or laravel. See how everything is arranged there. The way you write now will be remembered as a nightmare.

M
Michael, 2016-03-23
@Sing303

Read at least the first 2 lectures
www.intuit.ru/studies/courses/71/71/lecture/2112?page=1
It explains in detail all the requirements for quality software and how you can fulfill all these requirements using OOP, and why it is impossible, for example, procedural style.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question