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. cuda yv12_to_rgb24

    前言 项目需要将yv12转rgb24,由于基于x86平台,开始就没多想,直接用ipp加速实现了,后来在评估项目瓶颈的时候发现,1080p的视频每一帧转换居然要花8ms,刚好项目里有用到nvidia g ...

  2. [ Openstack ] Openstack-Mitaka 高可用之 计算服务(Nova)

    目录 Openstack-Mitaka 高可用之 概述    Openstack-Mitaka 高可用之 环境初始化    Openstack-Mitaka 高可用之 Mariadb-Galera集群 ...

  3. [ Python - 12 ] 线程的信号量、标志位及队列

    线程的信号量 线程的信号量是同时允许一定数量的线程更改数据,主要作用在于限制线程的并发. #!_*_coding:utf-8_*_ # Author: hkey import threading, t ...

  4. python 判断平年还是闰年

    while 1: s = input('请填入一个年份:') s = int(s) year = False if s % 100 == 0 and s % 400 == 0: year = True ...

  5. RTP 学习

    1. RTP提供抖动补偿和数据无序到达检测的机制 2. RTP 本身并没有提供按时发送机制或其它服务质量(QoS)保证,它依赖于底层服务去实现这一过程. RTP标准定义了两个子协议,RTP和RTCP. ...

  6. Ajax 生成流文件下载(实现代码)

    // 绑定导出按钮    $("#btnExport").clickCheckLogin(function () { var form = $("<form> ...

  7. php关于private、protected、public的区别

    一句话总结: private 自己的 protected 父亲的 public 大众的

  8. Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)

    D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  9. boost::operators

    boost 的 operators 提供了comparison operators.arithmetic operators.operators for iterators 操作.虽然使用 C++ 的 ...

  10. tensorflow bilstm官方示例

    ''' A Bidirectional Recurrent Neural Network (LSTM) implementation example using TensorFlow library. ...