-
Which of the following are invalid names? Why?
-
Based on the example of the car in this chapter, think of an object you use every day. Identify a class for that object and write five actions you do with that object.
-
Given the list in exercise 2, use the following syntax:
-
Imagine that you owned a boat and a motorcycle in addition to a car. List the actions you would perform with each of these. Do you have any overlap between these actions?
-
Based on question 4, imagine you had a class called a Vehicle and an object called myVehicle that could be either a Car, a Motorcycle, or a Boat. What if you wrote the following:
-
In a procedural language such as C, you think about actions and then write code to perform the action on various objects. Referring to the car example, you might write a procedure in C to wash a vehicle and then inside that procedure write code to handle washing a car, washing a boat, washing a motorcycle, and so on. If you took that approach and then wanted to add a new vehicle type (see the previous exercise), do you see advantages or disadvantages to using this procedural approach over an object-oriented approach?
-
Define a class called Point that will hold a Cartesian coordinate (x, y), where x and y are integers. Define methods to individually set the x and y coordinates of a point and retrieve their values. Write an Objective-C program to implement your new class and test it.
Int playNextSong 6_05 _calloc Xx alphaBetaRoutine clearScreen _1312 z ReInitialize _ A$
[instance method];
to rewrite your list in this format.
[myVehicle prep]; [myVehicle getGas]; [myVehicle service];
Do you see any advantages of being able to apply an action to an object that could be from one of several classes?