Chapter 7

Questions for Chapter 6

1. How can you mark an attribute so that it will never change after it is first set?

A. +attrName

B. −attrName

C. attrName {readOnly}

D. attrName {query}

E. attrName {noChange}

F. attrName

2. How can you mark an attribute so that it has Class scope?

A. +attrName

B. −attrName

C. attrName {readOnly}

D. attrName {query}

E. attrName {noChange}

F. attrName

3. Which sort of ship would make a good Class?

A. Friendship

B. Leadership

C. Battleship

D. Transship

E. Ownership

4. Which sort of features can Instances have?

A. Slots

B. Parameters

C. Attributes

D. Faces

E. Operations

5. What letter labels an item that the query can change?

image

A. w

B. x

C. y

D. z

6. How does a DataType differ from a Class?

A. Only a DataType can have operations.

B. Only Class instances have identity even if all the attribute values are the same.

C. Only a Class can have slots.

D. Only a Class can participate in generalizations.

E. Only a DataType can use literals.

7. On what kind of UML Diagram(s) can Instances and Classes appear?

A. They can appear on any behavioral Diagram.

B. Instances can only appear on Object Diagrams.

C. Both Classes and Instances can appear on Object and Class Diagrams.

D. Classes can only appear on Class Diagrams.

8. What is the correct and complete UML 2.5 shape for an Instance Specification?

A. 

image

B. 

image

C. 

image

D. 

image

9. Which is a correct use of a typed Boolean Literal?

A. isSeniorCitizen = True

B. isSeniorCitizen = True or False

C. isSeniorCitizen = “False”

D. isSeniorCitizen = {myAge > 65}

E. isSeniorCitizen = 1

10. Examine the Class below. Which choice indicates an Instance that is named Michael?

image

A. 

image

B. 

image

C. 

image

D. 

image

E. 

image

11. In the following Class fragment, how many Types are named?

image

A. 0

B. 1

C. 2

D. 3

E. 4

F. 5

12. Which choice correctly assigns the price parameter to a matching default value? Do not define additional Types or utilize Opaque Expressions.

A. hailCar (price: Integer = 2.0,

B. hailCar (price: Integer = “2”,

C. hailCar (price: Real = 2,

D. hailCar (price: Float = 2.0,

E. hailCar (price: Real = 2.0 D + 00

13. If you wish to prevent the userID parameter in the hailCar operation from being changed, what would be the safest approach?

A. hailCar(userID, …

B. hailCar(−userID, …

C. hailCar(inout userID, …

D. hailCar(userID {readOnly}, …

14. The registerMyCar operation with the Ride Hailing app allows drivers to register, either Black or Yellow-colored cars. How would this best work to register a Black Car?

A. registerMyCar (isBlack: Boolean = True, isYellow: Boolean = False,

B. Assign Black to 0, and Yellow to 1, then registerMyCar (scheme: Integer = 0,

C. Create a ColorSchemeKind enumeration type, with literals “Black” and “Yellow”, then registerMyCar (scheme: ColorSchemeKind = “Black”,

D. Create a ColorSchemeKind enumeration type, with literals Black and Yellow, then registerMyCar (scheme: ColorSchemeKind = Black,

15. After you create a Driver instance, what would happen if you tried to create a second Driver with the same values for the attributes?

image

A. They would be the same driver as they have the same properties

B. You would have two drivers with the same properties

C. An exception would be raised.

D. The create operation would fail.

16. How should you indicate that an attribute is derived?

A. Place an {isDerived} before the attribute definition.

B. Place a “~” before the attribute definition.

C. Place a “/” before the attribute definition.

D. Place an “out” before the attribute definition.

17. How do you specify to pass an operation parameter (x) by reference?

A. operation(byReference x:Type)

B. operation(x:Type {isByReference})

C. operation(x:Type (isByValue = False))

D. operation(#x:Type)

E. It is not possible in UML to specify this.

F. operation (in x:Type)

18. What does the underline of anAttribute indicate?

image

A. The value of anAttribute cannot change, i.e., it is static.

B. All of the instances of Example see the same value for anAttribute.

C. None of the instances of Example requires an independent initialization of anAttribute.

D. The attribute is part of the state value.

Answers for Chapter 6

1. How can you mark an attribute so that it will never change after it is first set?

A. +attrName

B. −attrName

C. attrName {readOnly}

D. attrName {query}

E. attrName {noChange}

F. attrName

Discussion:

A—No, the “+” makes the attribute public, subject to change by anyone.

B—No, the “−” makes the attribute private, which protects from change from the outside, but operations within the class can still change them

D—No, {query} may be used on operations, to prevent the operation from changing attributes

E—No, the underline makes the attribute statically scoped. This is not related to changeability.

C—Yes, {readOnly} allows the adorned attribute to be set when the object is created, but only then.

2. How can you mark an attribute so that it has Class scope?

A. +attrName

B. −attrName

C. attrName {readOnly}

D. attrName {query}

E. attrName {noChange}

F. attrName

Discussion:

A and E—No, these are all variations on instance-scoped attributes

F—Yes, the underline makes the attribute Class scoped.

3. Which sort of ship would make a good Class?

A. Friendship

B. Leadership

C. Battleship

D. Transship

E. Ownership

Discussion:

A, B, and E—No, though these are nouns, they are abstract nouns and are unlikely to represent a Class.

However, they might make good associations or properties. We could treat them as Classes, if we wished to reify them by looking at persistent records, for example, a sales receipt might be considered as an Ownership (record)

D—This is a verb, it means to ship to an intermediate point, and then ship to the final destination. Transship would make an acceptable operation.

C—Yes, a Battleship is a concrete physical Class It is a large armored warship with a battery of heavy guns and has instances. By the way, no battleships remain in service or in reserve with any navy worldwide1.

4. Which sort of features can Instances have?

A. Slots

B. Parameters

C. Attributes

D. Faces

E. Operations

Discussion:

E and B—No, Operations do not appear on instances. Parameters are arguments to operations, and they do not appear on instances.

C—No, Attributes on a Class would appear as Slots on the instance.

D—No, Faces might appear on Actor cartoons, but not on instances.

A—Yes, a slot is the location than an instance holds the value of an attribute.

5. What letter labels an item that the query can change?

image

A. w

B. x

C. y

D. z

Discussion:

A and C—No, a query cannot change a value or state within the Class/type.

D—Yes, a query can return a value.

6. How does a DataType differ from a Class?

A. Only a DataType can have operations.

B. Only Class instances have identity even if all the attribute values are the same.

C. Only a Class can have slots.

D. Only a Class can participate in generalizations.

E. Only a DataType can use literals.

Discussion:

A—No, both Classes and DataTypes can have operations.

C—No, neither Classes nor DataTypes have slots, though their Instances may have slots.

D—No, both Classes and DataTypes can participate in generalizations

E—No, both Classes and DataTypes can use literals.

B—Yes, if the attributes are the same for a DataType, they have the same value. Class instances have intrinsic identity, which DataType instances do not have.

7. On what kind of UML Diagram(s) can Instances and Classes appear?

A. They can appear on any behavioral Diagram.

B. Instances can only appear on Object Diagrams.

C. Both Classes and Instances can appear on Object and Class Diagrams.

D. Classes can only appear on Class Diagrams.

Discussion:

A—No, Instances and Classes are part of the static model and generally, cannot appear on behavioral diagrams.

B—No, while Instances can appear on Object Diagrams, they also can appear on Class Diagrams.

D—No, while Classes can appear on Class Diagrams, they can also appear on Object Diagrams.

C—Yes, both Instances and Classes can appear on Object and Class Diagrams. They also can appear on Package Diagrams.

8. What is the correct and complete UML 2.5 shape for an Instance Specification?

A. 

image

B. 

image

C. 

image

D. 

image

Discussion:

A—No, this was the notation in the OML language for an Instance. OML was a competitor to UML. This shape is sometimes called a house. It is not part of UML.

B—No, this option omits the underline for the name and type.

C—No, though it is underlined, the shape is not correct.

D—Yes, this is correct. In UML, an instance takes the shape of the Classifier, in this case a Class. The title in the Title compartment is underlined.

9. Which is a correct use of a typed Boolean Literal?

A. isSeniorCitizen = True

B. isSeniorCitizen = True or False

C. isSeniorCitizen = “False”

D. isSeniorCitizen = {myAge > 65}

E. isSeniorCitizen = 1

Discussion:

A—Yes, the Boolean Literals are either True or False.

B—No. While the Boolean Literals are True or False; you can only assign an attribute or slot to one of these values.

C—No, this is a Literal String assignment.

D—No. While this might work, it is an assignment to an opaque expression in the form of a constraint.

E—No, this is an Integer Literal assignment.

10. Examine the Class below. Which choice indicates an Instance that is named Michael?

image

A. 

image

B. 

image

C. 

image

D. 

image

E. 

image

Discussion:
This question revolves around the distinction between the contents of a variable and the name of the variable2, and it also requires knowledge of the correct UML format for Instances.

A—Yes, this is an Instance of the Class Person. The name of the Instance is Michael. The name slot that this Instance has is unassigned.

B—No, because the Person field comes first followed by a blank Class field, this is an Instance called Person of an unspecified Class. The instance has a name slot assigned the value of “Michael.”

C—No, this is the Person Instance of the Michael Class. The Class name comes second in the title of an Instance Specification.

D—No, this is an anonymous instance of the Class Person. The name in the slot is “Michael.”

E—No, this is a Class named Person. It has “Michael” assigned to an attribute.

11. In the following Class fragment, how many Types are named?

image

A. 0

B. 1

C. 2

D. 3

E. 4

F. 5

Discussion:

E—Yes (4). The attribute (s) is typed (t), the parameter (w) is typed (x), the operation has a return type (z). In addition, the Class R is also a type, because all classes are also types.

12. Which choice correctly assigns the price parameter to a matching default value? Do not define additional Types or utilize Opaque Expressions.

A. hailCar (price: Integer = 2.0,

B. hailCar (price: Integer = “2”,

C. hailCar (price: Real = 2,

D. hailCar (price: Float = 2.0,

E. hailCar (price: Real = 2.0 D + 00

Discussion:

A—No, 2.0 is a Real or Decimal literal.

B—No, “2” is a String literal.

D—No, Float is not a UML type.

E—No, though, UML allows exponent forms, UML only accepts “E” as the pre-exponent character (e.g., 2.0 E + 00). Using the “D” here would make this an opaque expression. In several programming language (e.g., Fortran), using the D indicates a Double precision real number.

C—Yes, in UML a literal that looks like an Integer is compatible with the Real type.

13. If you wish to prevent the userID parameter in the hailCar operation from being changed, what would be the safest approach?

A. hailCar(userID, …

B. hailCar(−userID, …

C. hailCar(inout userID, …

D. hailCar(userID {readOnly}, …

Discussion:

B—No, the “−” indicates an attribute is private, and not accomplish anything on an argument.

C—No, a ParameterDirectionKind of “inout” indicates that the userID parameter can be changed because it includes the “out” direction.

D—No, {readOnly} only applies to attributes.

A—Yes, in UML the ParameterDirectionKind has a default of “in” if no direction is specified.

14. The registerMyCar operation with the Ride Hailing app allows drivers to register, either Black or Yellow-colored cars. How would this best work to register a Black Car?

A. registerMyCar (isBlack: Boolean = True, isYellow: Boolean = False,

B. Assign Black to 0, and Yellow to 1, then registerMyCar (scheme: Integer = 0,

C. Create a ColorSchemeKind enumeration type, with literals “Black” and “Yellow”, then registerMyCar (scheme: ColorSchemeKind = “Black”,

D. Create a ColorSchemeKind enumeration type, with literals Black and Yellow, then registerMyCar (scheme: ColorSchemeKind = Black,

Discussion:

A—No, although this might work, it would be difficult if there were many possible color schemes, requiring many additional flags.

B—No, although this might work, it produces difficult to maintain code. The designer or programmers for registerMyCar would have to remember the color scheme numbering.

C—No, these are string literals because of they are enclosed in “ ”.

D—Yes, this is a correct and appropriate use of Enumeration type. It is elegant, efficient, and easily maintainable.

15. After you create a Driver instance, what would happen if you tried to create a second Driver with the exact same values for the attributes?

image

A. They would be the same driver as they have the same properties

B. You would have two drivers with the same properties

C. An exception would be raised.

D. The create operation would fail.

Discussion:

A—No, this classifier is a Class. If it were a DataType, it would be labeled «DataType». Two instances of a DataType must have some difference in properties. Two instances of a class may have identical properties.

C—No, there is no indication in the model that this would cause a problem.

D—No, there is no indication in the model that this would cause a problem.

B—Yes, it is certainly possible to have two Class instances that have the same properties. We hope that the software would recognize that two drivers with the same license is potentially a problem.

16. How should you indicate that an attribute is derived?

A. Place an {isDerived} before the attribute definition.

B. Place a “~” before the attribute definition.

C. Place a “/” before the attribute definition.

D. Place an “out” before the attribute definition.

Discussion:

A—No, though {isDerived) might work as an uncommon property modifier when placed after the attribute definition.

B—No, the tilde “~” indicates Package Visibility; visibility to things in the same package.

D—No, “out” is used before an argument to indicate an argument direction. When we use “out”, it means whatever value the parameter has before the operation is first ignored and then replaced.

C—Yes, the solidus or slash “/” indicates that it is derived. Note that backslash “” is incorrect but it common to forget which direction it goes. Often, the UML tool will correct the direction.

17. How do you specify to pass an operation parameter (x) by reference?

A. operation(byReference x:Type)

B. operation(x:Type {isByReference})

C. operation(x:Type (isByValue = False))

D. operation(#x:Type)

E. It is not possible in UML to specify this.

F. operation (in x:Type)

A and D—No, these are wrong, as it is not possible to specify by value or by reference in UML.

F—No, though it is possible that this would be the implementation, the notation does not indicate pass by reference semantics.

E—Yes, this is correct. UML cannot specify the method of passing parameters. The intent is to make UML independent of the programming language. Many programming languages do not support pass by value or pass by reference.

18. What does the underline of anAttribute indicate?

image

A. The value of anAttribute cannot change, i.e., it is static.

B. All of the instances of Example see the same value for anAttribute.

C. None of the instances of Example requires an independent initialization of anAttribute.

D. The attribute is part of the state value.

Discussion:

A—No, while the underline indicates the attribute is “class-scoped”, commonly called “static”. In this case, “static” does not mean that the value cannot change.

C—No, I made this up to sound plausible without meaning anything.

D—No, while any attribute is potentially part of the state’s value, the underline does not add any significant meaning relating to state machines.

B—Yes, the underline indicates that the attribute is class scoped also called “static”. This means that the attribute is really an attribute of the class, and not that of an instance. All instances would see the same value for the attribute.


1Wikipedia, “Battleship” 2016.

2It is reminiscent of the situation in Lewis Carroll’s “Through the Looking Glass,” where the White Knight tries to explain to Alice the difference between the song’s name (“The Aged Aged Man”) and what the song’s name is called (“Haddock’s Eyes”), and what the song is called (“Ways and Means”).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.222.12