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.
Can we say objects have attributes, states and behaviors?的更多相关文章
- 论文阅读之 Inferring Analogous Attributes CVPR 2014
Inferring Analogous Attributes CVPR 2014 Chao-Yeh Chen and Kristen Grauman Abstract: The appear ...
- 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 ...
- 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 ...
- 转载:Practical UML™: A Hands-On Introduction for Developers
原文:http://edn.embarcadero.com/article/31863 By: Randy Miller Abstract: This tutorial provides a quic ...
- [中英对照]The sysfs Filesystem | sysfs文件系统
The sysfs Filesystem | sysfs文件系统 Abstract | 摘要 sysfs is a feature of the Linux 2.6 kernel that allow ...
- Applied Spatiotemporal Data Mining应用时空数据挖掘
Course descriptionWith the continuing advances of geographic information science and geospatialtechn ...
- 【笔记】jstree插件的基本使用
官网地址:https://www.jstree.com/ json返回参数格式:推荐第二种方式 不需要在重新拼接返回格式 不刷新页面重新初始化 jstree时使用:$.jstree.destroy() ...
- 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 ...
- Overview of the Oppia codebase(Oppia代码库总览)
Oppia is built with Google App Engine. Its backend is written in Python, and its frontend is written ...
随机推荐
- C++ Primer 阅读笔记:迭代器和容器 小结
原创 by zoe.zhang 0.写在前面的话 我是在2011年学的C++,但是那一年恰好是C++11新标准的一年,但是大学上学的C++还是基于C++98的风格的,使用的编译器也是VC6.0,啊, ...
- codevs 线段树练习ⅠⅡⅢ
1080 线段树练习 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 一行N个方格,开始每个格子里都有 ...
- layer close 关闭层IE9-浏览器崩溃问题解决
针对ayer弹出层在IE上关闭导致浏览器崩溃的问题: 导致原因: 查看src源码,layer.close关闭总方法中有这么一行: layer.close = function(index){ ] + ...
- python模块学习:Iterators和Generators
转自:http://www.cnblogs.com/zhbzz2007/p/6102695.html 1 迭代器: 迭代器,允许你在一个容器上进行迭代的对象. python的迭代器主要是通过__ite ...
- [thinkphp] U方法域名支持
域名支持如果你的应用涉及到多个子域名的操作地址,那么也可以在U方法里面指定需要生成地址的域名,例如: U('Blog/read@blog.thinkphp.cn','id=1'); @后面传入需要指定 ...
- 设置每个datanode里面的map数目,提高运行效率
首先可以通过hdfs.site.xml下面的dfs.block.size来设置数据的块大小,这个参数会决定map的总数目(4194304=4m) 然后通过mapred.site.xml下面的mapre ...
- 洛谷 P1093 奖学金【三级结构体排序】
题目描述 某小学最近得到了一笔赞助,打算拿出其中一部分为学习成绩优秀的前5名学生发奖学金.期末,每个学生都有3门课的成绩:语文.数学.英语.先按总分从高到低排序,如果两个同学总分相同,再按语文成绩从高 ...
- Hibernate 配置文件与实体类
今天在配置Hibernate的时候碰到了这样的错误: MappingException: Unknown entity 仔细想了一下,应该是因为我在开始时使用了 Configuration confi ...
- 模板—字符串—Manacher
模板—字符串—Manacher Code: #include <cstdio> #include <cstring> #include <algorithm> us ...
- hdu6155
hdu6155 题意 给出一个只由 \(01\) 组成的字符串 \(s\),有两种操作: 翻转区间 \([l, r]\) 查询区间 \([l, r]\) 有多少不同的子串 分析 首先考虑怎么统计区间有 ...