what is a member vs. a property

后端 未结 9 2198
灰色年华
灰色年华 2020-12-15 03:39

A friend who is new to OO programming asked me the difference between a Member and Property, and I was ashamed to admit that I couldn\'t give him a good answer. Since proper

9条回答
  •  心在旅途
    2020-12-15 04:28

    Both properties and methods are members of an object. A property describes some aspect of the object while a method accesses or uses the owning object.
    An example in pseudo-code:

    Object Ball
    Property color(some Value)
    Method bounce(subroutine describing the movement of the Ball)
    

    Where the ball is defined and given a color(property) while the method bounce is a subroutine that describes the how the ball will react on hitting another object.
    Not all languages have properties, i.e. Java only has fields that must be accessed by getters and setters.

提交回复
热议问题