zoukankan      html  css  js  c++  java
  • Can we say objects have attributes, states and behaviors?

    I was reading through Oracle's introduction to OOP concepts and I came across this description:

    Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Software objects are conceptually similar to real-world objects: they too consist of state and related behavior.

    My problem with that passage is that when describing state its mixes attributes there too. For instance, the name and color of a dog are its attributes, while it being hungry or thursty are its states.

    So in my opinion it's more accurate to break the characteristics of objects into three parts: attributes, states and behaviors.

    Sure, when translating this into a programming language I can see that the three-fold partition becomes a two-fold one, because both attributes and states will be stored into fields/variables, while behaviors will be store into methods/functions.

    But conceptually speaking it makes more sense to have the 3 things separate.

    Here's another example: consider a lamp. Saying that both the lamp size and whether or not it's turned on are states is a stretch in my opinion. The lamp size is an attribute, not a state, while it being turned on or off is a state.

    Or did I miss something?

     
    ------------------------------------------------------------------

    You are right in that objects consist of attributes, states, and behavior, if you define attributes to mean non-changing characteristics of an instance. As a matter of fact, it is important to make this distinction, because there exist objects which contain only attributes, (in your sense,) and no state; they are called immutable and they are very useful in programming.

    This three-part definition is indeed represented in programming languages, for example using the final keyword in Java or the readonly keyword in C# to denote instance data which may not change throughout the lifetime of the instance.

    I have to add, though, that non-changing instance data are usually not called attributes. We tend to speak of them as 'final' or 'readonly' or 'constant data' depending on which language we are using. The proper term for them would be 'invariants', but then this word is not frequently used in this sense; it is more often used for other things.

     
  • 相关阅读:
    one-hot 编码
    typeError:The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python scalars,strings,lists.numpy ndarrays,or TensorHandles.For reference.the tensor object was Tensor...
    tensorflw-gpu 运行 。py程序出现gpu不匹配的问题
    空间金字塔池化 ssp-net
    随便说一说bootstrap-table插件
    初识 .NET平台下作业调度器——Quartz.NET
    在VS中关于MySQL的相关问题
    教你记住ASP.NET WebForm页面的生命周期
    国内流行的两大开源.net微信公众平台SDK对比分析
    一次利用MSSQL的SA账户提权获取服务器权限
  • 原文地址:https://www.cnblogs.com/oxspirt/p/9256861.html
Copyright © 2011-2022 走看看