What is encapsulation with simple example in php?

前端 未结 14 1500
谎友^
谎友^ 2020-12-08 02:27

What is encapsulation with simple example in php?

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 02:53

    People seem to be mixing up details of object orientation with encapsulation, which is a much older and wider concept. An encapsulated data structure

    • can be passed around with a single reference, eg increment(myDate) rather than increment(year,month,day)
    • has a set of applicable operations stored in a single program unit (class, module, file etc)
    • does not allow any client to see or manipulate its sub-components EXCEPT by calling the applicable operations

    You can do encapsulation in almost any language, and you gain huge benefits in terms of modularisation and maintainability.

提交回复
热议问题