Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 8. Categories, Posing, and Proto... > Categories: Putting It All Together

Categories: Putting It All Together

In the previous two tasks, you created Class1 and extended it using categories. In this task, you’ll put the Class1 class and its extension category to work.

To use the base class with categories:

1.
Create a new program named main.m.

2.
In main.m, enter the code shown in Listing 8.7.

This code includes the class1.h and class1extender.h header files to make sure your code knows about Class1 and its extending categories.

3.
In main.m, add the code to create a new object of Class1 (Listing 8.8).

4.
In main.m, add the code shown in Listing 8.9.

This code calls the print method built into the Class1 class and the print2 method with which you’ve extended Class1.

5.
Save main.m.

6.
If you’re using Linux, UNIX, or Windows, create a new makefile named GNUmakefile.

7.
In GNUmakefile, enter the code shown in Listing 8.10.

8.
Save GNUmakefile.

9.
Run the main.m categories program.

You should see the output from both the print method and the extending print2 method:

This is Class 1.
This is Class 1 extended.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial