Object oriented programming - class design confusion

前端 未结 13 1751
你的背包
你的背包 2021-02-05 22:01

I am trying to wrap my head around object oriented programming.

My understanding is that we have objects so we can design our programs to mirror real-life objects.

13条回答
  •  醉梦人生
    2021-02-05 22:31

    Most human languages follow a sentence structure (For simple statements) of Subject Verb Object

    In OOP languages like c++, not entirely ironically, the object is the object, and it comes first, so the normal order is reversed:

    So this is the 'basic' pattern in c++ :-

    object.verb( subject );
    

    This is actually rubbish. Most classes are designed with a subject.verb(object) interface. Knowledge of SVO however does allow one to test whether or not a class interface has been designed to be the correct way around (in this case, it has not).

    That said, there are a large number of human languages that are naturally OVS, or some other variant where the typical english order is reversed. When dealing with internationally developed software other developers might have a different idea as to the correct and normal order of subjects, and objects in a simple statement.

提交回复
热议问题