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.

 

Can we say objects have attributes, states and behaviors?的更多相关文章

  1. 论文阅读之 Inferring Analogous Attributes CVPR 2014

    Inferring Analogous Attributes     CVPR  2014 Chao-Yeh Chen and Kristen Grauman Abstract: The appear ...

  2. Introspection in Python How to spy on your Python objects Guide to Python introspection

    Guide to Python introspection https://www.ibm.com/developerworks/library/l-pyint/ Guide to Python in ...

  3. Cognition math based on Factor Space (2016.05)

    Cognition math based on Factor Space Wang P Z1, Ouyang H2, Zhong Y X3, He H C4 1Intelligence Enginee ...

  4. 转载:Practical UML™: A Hands-On Introduction for Developers

    原文:http://edn.embarcadero.com/article/31863 By: Randy Miller Abstract: This tutorial provides a quic ...

  5. [中英对照]The sysfs Filesystem | sysfs文件系统

    The sysfs Filesystem | sysfs文件系统 Abstract | 摘要 sysfs is a feature of the Linux 2.6 kernel that allow ...

  6. Applied Spatiotemporal Data Mining应用时空数据挖掘

    Course descriptionWith the continuing advances of geographic information science and geospatialtechn ...

  7. 【笔记】jstree插件的基本使用

    官网地址:https://www.jstree.com/ json返回参数格式:推荐第二种方式 不需要在重新拼接返回格式 不刷新页面重新初始化 jstree时使用:$.jstree.destroy() ...

  8. Functional Programming without Lambda - Part 1 Functional Composition

    Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...

  9. Overview of the Oppia codebase(Oppia代码库总览)

    Oppia is built with Google App Engine. Its backend is written in Python, and its frontend is written ...

随机推荐

  1. go语言的定时器

    package main import ( "fmt" "time" ) func main(){ //创建一个定时器,时间为2s,2s过后会自动往通道里面写入 ...

  2. vue学习记录:vue引入,validator验证,数据信息,vuex数据共享

    最近在学习vue,关于学习过程中所遇到的问题进行记录,包含vue引入,validator验证,数据信息,vuex数据共享,传值问题记录 1.vue 引入vue vue的大致形式如下: <temp ...

  3. Spring MVC 基础篇4

    Spring MVC Controller中返回数据到页面 1.使用ModelAndView 进行数据返回到请求页面 2.利用Map类型的入参进行Controller返回到页面上 3.将数据放到Ses ...

  4. 【hdoj_2111】SavingHDU

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2111 题目理解:给出一个口袋的容量,若干种宝物的单价和体积,单个的宝物可以分割,待求的是最多能装价值多少的 ...

  5. css样式表中的样式覆盖顺序(转)

    有时候在写CSS的过程中,某些限制总是不起作用,这就涉及了CSS样式覆盖的问题,如下 Css代码   #navigator { height: 100%; width: 200; position:  ...

  6. LayerDate渲染多个class出现闪现问题的解决

    填写表单的时候有时候会需要添加一行表单的业务逻辑,而表单要用到LayerDate的话便不可避免的出现多个class的情况 这种情况下后面的class是无法渲染的,layerDate官网提出了解决方法: ...

  7. [/wp_active.php]

    if ( !is_multisite() ) { wp_redirect( site_url( '/wp-login.php?action=register' ) );//将用户重定向到一个预先制定的 ...

  8. HDU 2537 8球胜负(模拟)

    /*这是一个模拟题,模拟一种台球的进球过程,并且判定胜负. 对于输入的字符串,如果出现R则红方记1分,如果出现Y则黄方记1分. 最后根据哪一方打进黑球和得分情况判定胜负. 程序说明: 这里给出两个C语 ...

  9. RabbitMQ (七) 订阅者模式之主题模式 ( topic )

    主题模式和路由模式很像 路由模式是精确匹配 主题模式是模糊匹配 依然先通过管理后台添加一个交换机. 生产者 public class Producer { private const string E ...

  10. 算法-桶排序(Bucket sort)

    本文由@呆代待殆原创,转载请注明出处. 简介:这个排序算法不属于比较排序,在平均情况下他的时间代价是O(n),并且它假设它的输入数据均匀的分布在一个固定的区间里. 思路:桶排序假设他的输入均匀的分布在 ...