Study Cards on attribute, compartment, specification
Now, we’ll emphasize the notation, capability, and features of an object/instance specification.
What is an "Object" and what is an "Instance" ?
An “instance” is the same thing, with an emphasis on the fact that there is a class or a type (a classifier) involved, i.e., an “instance” of a class
A class designates a set of instances, while an Instance Specification identifies one of a potentially smaller set.
If you don’t indicate a class, the instance specification is indicating that the class isn’t important – and an instance of any class will do.
If you don’t indicate the name, then the name of the instance isn’t important. The name compartment can also display any relevant stereotypes.
The literal value must be compatible with the types of the attributes.
Often the attribute types are repeated after the slot name, as shown below.
title: String = “Tom Sawyer”
There are no ...... Or ..... compartments.
There are no operations or signals compartments.
The elements that would be in these compartments would be captured in the class definition and do not need to be repeated.
Similarly, in the slots compartment, don’t repeat slots unless you really care about their values in this circumstance.
we could have changed the class definition to have a name:String attribute and correspondingly change the title slot to be a name slot.
In such a case, the name of the instance would still be “myBook” and the name attribute of the instance would be “Tom Sawyer.”
- Higher grades + faster learning
- Don't study anything twice
- 100% sure, 100% understanding