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 ...
随机推荐
- [设计模式-行为型]状态模式(State)
一句话 在一个类的对象中维护状态的类的对象 概括
- MyEclipse2015+Tomcat8.0+Maven3.3项目环境搭建
之前一直用自己的笔记本进行web项目的开发,实验室配了一台台式机,软件和环境都需要重新配置和安装.最近准备用SSM(Spring,SpringMVC,MyBatis)框架编写一个图书管理系统,主要使用 ...
- Android xmlpull 方式解析xml文件
1.新建一个xml文件,放在res/xml目录下 <?xml version="1.0" encoding="utf-8"?> <citys& ...
- 前端读者 | 别人写的css,你敢用吗?
本文来自@yeaseonzhang:链接:http://yeaseonzhang.github.io/2018/04/10/%E5%88%AB%E4%BA%BA%E5%86%99%E7%9A%84cs ...
- 能Ping通外网但就是不能打开所有网页的解决办法
我碰到过两台电脑有这个问题.打百度的ip可以,但打网址不行.我记得是某个木马改动了三个dll文件,然后你电脑删了该木马,却没有恢复那三个dll所致.你google下dns恢复,注册dll关键字,一共要 ...
- Visual Studio Code更改语言
参数地址:Visual Studio Code 设置Display Language介绍 在Visual Studio Code中使用快捷键Ctrl + Shift + P可以打开命令行 在local ...
- 实例教程:1小时学会Python(转)
1 序言 面向读者 本文适合有经验的程序员尽快进入Python2.x世界.特别地,如果你掌握Java和Javascript,不用1小时你就可以用Python快速流畅地写有用的Python程序. Pyt ...
- 1.1(Spring学习笔记)Spring-事务基础
一.Spring 事务 Spring提供对事务支持的核心包是spring-tx-4.3.6.RELEASE包. 该包类有三个核心接口,提供对事务的支持: 1.1PlatformTransactionM ...
- 3.2常用类(java学习笔记)String与StringBuffer
一.String String又称不可变字符序列. 我们看JDK源码中用于字符存储的数组有final修饰,final修饰变量就代表变量不能改变. 我们可以看API文档中对String的描述. Stri ...
- 西电大第十六届程序设计竞赛 A-GRE
题目描述 不愤不启不悱不发,王萌萌为了能够成功上研,开始刻苦背GRE单词,但是由于她过于刻苦,在背会英语单词的同时,把中文读音忘了.于是王萌萌又开始复习起中文发音,她先从数字开始复习起... ...