无法理解对象状态,行为和身份? [英] Trouble understanding Object State, Behavior, and Identity?
问题描述
我的教授指示我在页面上进行自我介绍,就好像我是一个对象一样,并且必须解决三件事:
1)对象状态,2)行为和3)身份.
I have been instructed by my professor to introduce myself on a page as if I were an object, and that I must address three things:
1) Object State, 2) Behavior, and 3) Identity.
但是,对于如何做这样的事情,我还是很困惑. (我已经阅读了必须解决的三个属性,但是我不知道如何将其应用于一个人.)
例如,有人告诉我狗的状态,名称和颜色等.以及行为,例如走路,吠叫或摇尾巴.
However, I am still really confused as to how I would go about doing something like this. (I have read about the three attributes I must address, but I don't know how I would apply it to a person).
For example, I was told a dog would have States, such as name, color, and breed; as well as Behaviors, such as walking, barking, or wagging their tail.
我会做类似的事情吗?
Student me = new Student();
System.out.println(me.getName()); //a state?
System.out.println(me.getCurrentActivity()); //A behavior? (if it were to return watching TV or something)
System.out.println(me.get....()); //???
还是我在这里得到一个完全错误的想法?
Or am I getting the completely wrong idea here?
推荐答案
对象的特征是:
状态: 对象有什么,学生有名字,姓氏,年龄等
State: what the objects have, Student have a first name, last name, age, etc
行为: 对象做什么,学生参加了面向初学者的Java"课程
Behavior: what the objects do, Student attend a course "Java for beginners"
身份: 什么使它们唯一,学生有学生ID号或唯一的电子邮件. (这在实现equals方法时很重要,以确定对象是否不同)
Identity: what makes them unique, Student have Student-ID-number, or an email which is unique. (this is important when implementing the equals method, to determine if the objects are different or not)
Student john = new Student("John");
john.setCurrentActivity("Learning Java");
john.setAge(21);
john.setWeight(173);
john.setAddress(...);
john.setHobbies(...);
您就可以弄清楚吸气剂.
and you can figure out the getters.
public class Student {
private String name;
private int age;
//etc
// construct a new student
public Student(String name) {
this.name = name;
}
public setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
}
一个汽车对象的插图,我发现它可能对您有帮助...
An illustration of a Car object, which I found that might help you some...
汽车状态:
- 速度
- RPM
- 齿轮
- 方向
- 燃油水平
- 发动机温度
行为:
- 换挡
- 快/慢
- 倒退
- 停止
- 关闭
身份:
- VIN
- 车牌
这篇关于无法理解对象状态,行为和身份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!