[ Team LiB ] Previous Section Next Section

Workshop

Quiz

1:

We did not want our Command::execute() method to be overridden by code in child classes. How did we enforce this?

2:

Briefly, how did we ensure that there was only one DataStore object in our system at any one time?

3:

We said that the practice of a method calling and using abstract methods defined in the same class was an example of a design pattern. What was its name?

4:

Which keyword did we use to check that an object we had instantiated belonged to the Command family?

5:

How did we ensure that our Command class status flags were unchangeable and available via the class rather than particular object instances?


Answers

A1:

You can prevent a child class from overriding a method by declaring it final.

A2:

We made the DataStore object a Singleton. That is, we made its constructor private so a DataStore object could be instantiated only by a static method in the DataStore class itself. The static method can ensure that it returns only the same single instance of a DataStore object when it is called.

A3:

A method calling and using abstract methods defined in the same class is an example of the template method pattern.

A4:

We can use instanceof to test the type of an object.

A5:

You can declare constant properties with the const keyword. A constant property is unchangeable at runtime and is available via the class rather than object instances.


    [ Team LiB ] Previous Section Next Section