Listing 1 shows a Person class implementing Serializable.
清单1显示一个实现Serializable的person类。
PersonV2, shown in Listing 3, introduces a field for gender to the original Person class.
如清单3 所示,PersonV2在原先Person 类的基础上引入一个表示性别的新字段。
Listing 1 is a recap of the simple Person class I've used in my introduction to db4o so far.
清单1重述了我在介绍db4o时一直使用的一个简单类person。
Consider a Serializable Person class that defines a friend of its own, as shown in Listing 1.
Serializable Person类定义了一个它自己的友元,如清单1所示。
In Listing 9, I've created a person class to represent the person element defined in Listing 6.
在清单9中,我已经创建了一个Person类来表示在清单6中定义的person元素。
In Listing 10, you can see the mapping code that maps an instance of the above-defined Person class.
在清单10中,您可以看到对上面定义的Person类的实例进行映射的代码。
So, for example, say you needed the list of children in the Person class to always be sorted by age.
例如,假设您需要person类中的孩子总是按年龄排序。
Use this tool to draw a line from the Employee class to the Person class to signify this relationship.
用该工具从Employee类向Person 类画一条直线就可以表示这种关系。
As you add validation methods to the Person class, the call to valid? will automatically become smarter.
随着您向Person类中加入验证方法,valid ?会自动的根据这些方法进行验证。
Listing 4 provides enough information for Jenabean to save and load instances of the Person class reliably.
清单4为Jenabean提供足够的信息来可靠地保存和装载person类实例。
There's a bit of code duplication in the Person class, but I'll leave that for a later refactoring exercise.
在person类中有一些重复的代码,但我把它留给稍后的重构练习。
If a Person class hasn't been added to the model yet, it asserts the new class as an instance of owl: class.
如果person类还没有添加到模型中,它将断言一个新类作为owl: Class的实例。
To create the Person class, click on the class icon in the tool palette and draw a box on the design surface.
要创建person类,单击工具面板上的Class图标,并在设计界面中画一个方框。
Obviously, I don't have a Person class yet so my test is having some trouble running — JUnit gives me a red bar.
显然,我还没有person类,所以运行该测试会出现问题—JUnit给出了一个红条。
I show that in my model by adding a separate Person class and creating associations to the Victim and Witness classes.
我通过以下方法在我的模型中展示这一点:添加一个单独的person类,并创建到Victim和witness类的关联。
Since the Person class is what the app's data access layer returns, it is definitely not suited for consumption by the UI.
由于Person类是应用的数据访问层返回的东西,它绝对不适合直接被UI使用。
Let's say that I have a Person class which has a spouse property, so that the spouse of a spouse point to the same object.
我们假设有一个Person类,它有一个spouse(配偶)属性,以便spouse的spouse指向同一个对象。
This is where almost every object-oriented programming textbook starts: you have a Person class with fields like Name and Age.
这就是几乎每一个面向对象的编程教材开始的地方:您具有包含类似Name和 Age 字段的Person类。
Knowing that Serialization allows for refactoring, let's see what happens when we decide to add a new field to the Person class.
既然已经知道序列化允许重构,我们来看看当把新字段添加到person类中时,会发生什么事情。
For example, when the Person class was created, it displayed syntax errors because one of its attributes, Address, was undefined.
例如,当person类被创建时,它显示语法错误是因为它的一个属性address没有定义。
You can use Eclipse's refactoring tools to easily extract an interface from the Person class in Listing 3. Let's call that a Thing.
您可以使用Eclipse的重构工具从清单3中的Person类轻松提取一个接口。
For example, if you were to add height and weight to the Person class, you would need to update both tables, which is a lot of work.
例如,如果要向Person类添加高度和重量,就需要同时更新两个表,它会涉及很多工作。
Suppose the sensitive data in the Person class were the age field; after all, a lady never reveals her age and a gentleman never tells.
假设person类中的敏感数据是age字段。毕竟,女士忌谈年龄。
You have a Person class that includes some basic attributes (like name and phone number) and also points to an OfficeLocation, which is also an object class.
其中Person类包含一些基本的性质(比如姓名和电话),同时指向另一个对象类OfficeLocation。
What we need, therefore, is the serialVersionUID field, which is calculated by running the JDK serialver command against the original (or V1) version of the Person class.
因此,我们需要serialVersionUID字段,它是通过对原始(或V1)版本的Person 类运行JDKserialver命令计算出的。
They perfectly retain the semantics of the POJO while drastically reducing the amount of code you need to write. Listing 9 shows a "shorthand" person class written in Groovy
它们完全保留了POJO的语义,同时显著减少了需要编写的代码量。
As I've done in previous articles in this series, I'll use the Person class as a starting point for exploring Scala's inheritance system. Listing 1 shows the Person class definition.
与本系列之前的文章类似,我将使用Person类作为起点,探索Scala的继承系统。
Finally, you can diagram the relationship between the classes by clicking on the Association button (fifth from the left) and drawing a line from the Person class to the Address class.
最后,您可以单击association按钮(左起第五个),绘制一条从person类指向address类的线段,从而绘制这两个类之间的关系图。
If there was a defect in the Person class, there would most likely be a defect in the Employee class as well because it appears as though the implementation was copied between the two.
如果person类中有缺陷,则employee类中也很可能有一个缺陷,因为看上去似乎实现是在两个类之间复制的。
For example, in Figure 3 the solid diamond indicates that the relationship is a composition — in other words, that instances of the address class can only exist within the context of a person class.
比如,图3中的实心菱形表示这里是组合关系——换句话说,address类的实例只能存在于person类的上下文中。
应用推荐