Зачем (не)нужны геттеры?

/ ( Symfony PHP) . : - , , . .

getHumanFactory().getHuman().getDoneWork().getWorkTime()


, . — , .

class Article {
     private String name

     public function getName(): String {
          return this.name
     }
}

. , «»: «», «», «», «». — . -, / .

, . «, » «, , ». « » - , «».

, . , , , — .

getValue() throw WhyDoYouNeedIt? {}


- — 1917, -, , .

-? «» - «» ?

-, , , ( ), .

«» , -. - ? ? , , , ? — «» -, -, .

doEverythingEverywhere(world.getGod())


-. , . . , . ? , — .

:

class Order
{
     private Status status
     private Boolean closed

     public function getStatus(): Status {
          return this.status
     }

     public function setClosed(Boolean closed): void {
           this.closed = closed
     }
}

, / . , , . , , … , :).

- - :

if(order.getStatus() == input.getStatus()) {
      order.setClosed(true)
}

. — . — , , - , , , . : , , .

: , , .

CQRS, - .

!

All Articles