19.15 Assignments


1. What is the difference between a class and a module for implementing ADTs?

2. What kinds of components may an object have?

3. What do you call the generation of a specific object from a declared class?

4. Describe two approaches to component visibility for clients of a class and say which one was taken in Modula-2.

5. What does the concept of an immutable entity apply to in OOM-2?

6. What parts of a Modula-2 class are visible to a subclass?

7. What is the difference between objects with value semantics and those with reference semantics? Which approach does Modula-2 take?

8. What is the difference between a reference and a pointer?

9. What is the difference between an object definition and an object declaration?

10. What is the difference between a traced class and an untraced class?

11. What may a traced class not have in it?

12. What is the difference between a safeguarded module and an unsafeguarded one?

13. What may a safeguarded module not have in it?

14. What is another name for an object component?

15. Why is a method sometimes called a message?

16. In what way are Modula-2 classes like modules, and in what ways are they like records?

17. How is a Modula-2 object instantiated? How is it initialized?

18. May a Modula-2 object be manually destroyed? If so, under what circumstances?

19. What is meant by inheritance?

20. What is the purpose of inheritance?

21. What restrictions does OOM-2 place on what can be inherited and from where?

22. What kinds of components does OOM-2 allow to be overridden, and how is this done?

23. How does one access an overridden component?

24. What is the difference between static type and dynamic type?

25. If a chain of subclasses is declared, and an object is instantiated in the last child on the chain, is it assignment compatible to a variable of the eldest parent class? What about the other way around?

26. What is the GUARD statement for? In what way is it like a CASE statement and in what way is it like a WITH statement? How is it an assertion?

27. What is unusual about the semantics of ISMEMBER?

28. What is the difference between the way OOM-2 treats constants and type components, on the one hand, and attribute variables and methods on the other?

29. What imports are necessary when using untraced OOM-2 classes?

30. How may two classes refer to each others' declarations (or definitions)?

31. How does an object get access to itself?

32. Why does OOM-2 use single inheritance rather than multiple inheritance?

33. Propose a means (some syntax) that would, if included in OOM-2, avoid the problems of multiple inheritance.

34. What is an abstract class?

35. Some implementations do no implement traced objects, only untraced ones. What else will be missing from such implementations?

36. Determine whether your implementation allows you to turn garbage collection off.

37. In the example of section 19.11, there was no generic module for Vectors. Consider the chapter on generics carefully, and explain why it is not a simple matter to interpose a generic module for vectors between the generic module for Tuples and the module for vectors of a specific length. What would have to be done to accomplish this?

38. What change would have to be made to the base language in order to better accommodate classes in generic definition modules inheriting from classes in other generic definition modules?

39. Some languages are designed without any pointers, just reference variables. Thus, they have no untraced memory allocation at all (not just none for objects) and all memory allocated dynamically is traced by the garbage collector. What are the pros and cons of such an approach?

40. In some languages, class declaration is done by saying what class the new one is a subclass of. Show that this implies the existence of a standard identifier that names a particular built-in class. What would you call such a class?

41. Give an example to illustrate that allowing user defined operator overloading for OOM-2 would make life easier for the users of classes.


42. Create a series of derived classes to illustrate the constructor and destructor chain order.

43. Devise a means to test whether there is a greater overhead (time) associated with sending a message to an object (invoking a procedure that is a method) or calling a procedure containing the same code directly.

44. Consider the abstract class demonstration in section 19.8. Add proper commenting, better verbiage in the output, and the classes Triangle, Parallelogram, Rhombus, Trapezoid, and regular n-gon to the family, each in an appropriate place in the class hierarchy.

45. Complete and test the suite of objects in section 19.11.

46. Use the class points to implement a class line (using two points.)

47. Add a generic vector module to the example of section 19.11. See question 37.

48. Complete and test the suite of objects in section 19.12.

49. Implement a database for your Church, business, or hobby using an object oriented approach. Be sure to do a careful design of your chart of classes and their contents before writing any code.

50. Implement and test the data type fraction as a class. Include standard operations, reduction to lowest terms, and retrieval of numerator and denominator, as well as a display procedure.

51. Derive a complex number class from the suite of classes in section 19.11.

52. Design, implement and test a class for a deck of standard playing cards, including a procedure to deal hands of Bridge.

53. Use the same class CardDeck from the previous question to implement a game of solitaire.

54. Solve the eight queens problem using objects.

55. Solve the knight's tour problem using objects.

56. Implement a linked list as a class.

57. Derive a queue class from the above list class.

58. Derive a priority queue class from the above queue class.

59. Produce a concordance program that examines a text file and produces a sorted list of all the words in the file, their frequency, and a means to display the word in the contest of its original occurrences.

60. Implement a binary tree as a class.

61. Implement a quicksort as a class.

62. Use GraphPaper or other graphics capabilities on your computer to implement a bouncing ball on the screen as an instance of a class ball.