A
A
Alexander2016-12-23 01:07:02
OOP
Alexander, 2016-12-23 01:07:02

What are the benefits of OOP?

He will study and understand OOP, everything is cool - like it and want it, very convenient! Here I am sitting and thinking about its practical application, where to use it?) Where do you most often use classes? It is clear that there are gurus who have the entire application in OOP, the question is where is it better for a beginner to use it?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
X
xmoonlight, 2016-12-23
@SmoKE_xD

A role object in a project is a class.
Examples of roles (using a toaster as an example): user, question, answer, comment, notification, tag, feed.

O
OnYourLips, 2016-12-23
@OnYourLips

here the question is where it is better to use it for a beginner?
Everywhere.
Start using someone else's code as much as possible, and learn.
Master the composer tool, and connect libraries through it.
For example, read the yml file via symfony.com/doc/current/components/yaml.html
It is clear that there are gurus who have an entire application in OOP
Even junior.

T
ThunderCat, 2016-12-23
@ThunderCat

The profit of OOP is that there is an object and properties that you don’t need to know inside, it’s enough to know what to input and what will come out at the output, which is basically what almost all the main modern frameworks are based on - you take it and use it. It's like saying - "I shaved with a Vest, everything hurt, it's comfortable, high-quality, beautiful, but I myself can forge an ax and sharpen it sharper - it will be almost the same! What is the profit?".

E
Evgeny Kumanin, 2016-12-23
@jackkum

There are many useful things in object-oriented programming.
For example inheritance.

// describe interfate of engine
interface IEngine {
  public function getAcceleration();
  public function getPower();
}

// abstract implementation of engine
abstract class Engine implements IEngine {

  /**
   * Engine acceleration
   */
  protected $_acceleration = 0;

  /**
   * Engine power (h/p)
   */
  protected $_power = 0; 

  public function getAcceleration() {
    return (int) $this->_acceleration;
  }

  public function getPower() {
    return (int) $this->_power;
  }
}

// extending from engine implementation
class V12 extends Engine{
  protected $_acceleration = 0.0005;
  protected $_power = 300; 
}

// describe interface of the car
interface ICar {
  public function setEngine(IEngine $engine);
  public function accelerate();
}

// abstract implementation of engine
abstract class Car {

  /**
  * Engine of the car
  * @var IEngine
  */
 protected $_engine;

 /**
  * Speed of the car
  * @var Float
  */
 protected $_speed = 0;

 public function setEngine(IEngine $engine){
  $this->_engine = $engine;
 }

 public function accelerate() {
  if( ! ($this->_engine instanceof IEngine)){
    throw new Exception("Wrong type of engine");
  }

  $this->_speed += $this->_engine->getAcceleration();
 }
} 

class MyCar extends Car {
 public function __construct(){
   $this->setEngine(new V12());
 }
}

$car = new MyCar();
$car->accelerate();

E
evgeniy_lm, 2016-12-23
@evgeniy_lm

OOP is primarily about simplicity and speed of development

A
Alexander Sharihin, 2016-12-23
@Pinsky

OOP is a representation of real and speculative objects in the form of formalized entities.
And WEB development without OOP is often like hell. I highly recommend all the same to try to immerse yourself in the wonderful world of OOP)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question