Am I missing the point of object oriented programming?

Recently, I took on the task of trying to learn OO programming. It has been about three months since I started, but I think it might not make sense, because I prefer static methods (which seem "easier" to me).

Example

This is what a typical DB query looks like in my code.

$bindings = array(':name'=>$articleName);

Db::query('SELECT id, name, title, image, content FROM ' . CONFIG_MYSQL_TABLE_PREFIX . 'articles WHERE name = :name LIMIT 1', $bindings);

And this is how I resize / crop / cache images

$image = Img::thumbnail($imagePath, 200);

$imgHtml = '<img alt="' . $this->getTitle() . '" src="' . '' . $image['src'] . '" width="' . $image['width'] . '" height="' . $image['height'] . '" />';

Both static methods use a singleton pattern. the first creates one PDO, and the second creates one ImageResize class, which I found in Google code.

If these are two objects, if I really wanted to call it object-oriented programming? i.e.

$db = new Db();

$image = new Image($src, $width, $height);

? , , . , , <

: , , , ? ?

Update

. , , , , .

, OO, .

+3
6

, imho PHP - , PHP -. , . , . . .

, PHP . HTTP- PHP ( ), , . : " ?" (, , "a ha!" ), PHP. () , .

?

"" C, Java, ++ , , , . PHP CGI 90- ( , , ).

, : , .

, . , . (, preg_replace_callback, eval()/create_function()).

, PHP -, , PHP 5 OO - "", , PHP, . , , Java, , , , .

, OO, , PHP. PHP , , HTTP- (, , , , ), , .

+9

- - , , . "", Smalltalk.

, , " " . , .

, , . , , , , , , OO.

+7

, ... , php perl - , ,

, , , , ; , , .

+3

OO - .

, , -, Db:: query, , , , , :

  • mutli-threading

, - , ?

Db , , .

, , .., , , , .

, , .

, , , , OO. ( ) , , , , , , , .

+1

OO, PHP. PHP. , , :

- -

- Python. Python, , OO, OO, , . , OO.

+1

OO . , . OO , , .

, , , , OO. OO , ; OO .

0

Source: https://habr.com/ru/post/1704054/


All Articles