Is it worth making get and set methods in OOP?

前端 未结 4 665
执念已碎
执念已碎 2020-12-14 10:37

I have seen some some projects in which classes are having get and set methods to manipulate insert data. Let me have an example here :

    class Student ext         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 11:10

    Making setters and getters helps enforce OOP encapsulation. Im not sure for PHP, but for many other languages (Java, C++), a good IDE (eclipse/netbeans) will auto-generate these setters and getters for you.

    It may not be immediately obvious for simple types, but if any sort of more complex processing has to be performed, then it becomes more obvious.

提交回复
热议问题