Outside of one exercise which challenged me greatly, chapter 9 was not as bad as the prior ones. This chapter brought forth a bunch of interesting new concepts. Polymorphism, which seems natural to me allows one to use the same method name in different classes. The idea of encapsulation which I learned earlier on kind of goes hand in hand with this idea. Next I have data typing and data binding which allows me to use an id data type in the place of class objects. Using this along with polymorphism, allows one to change classes on the fly while being able to employ the same methods. Methods such as print thrive in this regard.
Another concept of asking questions about classes enables you to find out if an instance is a member of a class (direct) or is a descendent of a class (kind of). Then I learned about using selectors (confusing!!!) to determine if certain methods belong to a certain class or if a class has certain methods. From what I gather, there are many such selectors that go beyond what is in the current chapter and outside the scope of the book.
Lastly, the chapter got a little into exception handling with try and catch. I am excited about this as I was curious about exception handling works. However, the compiler is so good at picking up on errors that it was a little challenging for me to come up with a scenario to get the program will compile and also catch and deal with an error. To do this, I employed what I learned earlier in the chapter about data typing to invoke a method that had an argument that was not supposed to be there. It worked and the catch message appeared.
As for the exercises, I did them all pretty well except for the very challenging exercise #4. Wow, applying the data typing/binding throughout the class methods in the main and in the interface and implementation files was very confusing. I had to go on the Kochan help area to see how people dealt with this. In the process I learned that you can't use dot syntax with ids. Moreover, I also learned then when you invoke a setter method with variables that are synthesized, you have to capitalize the first letter of the variable after the word "set". For example, if you have a synthesized variable "real" and you want to set "real", you would have to do "setReal". Why the "r" is capitalized is beyond me. The best reason I have seen is that it is a "convention". I will live with that.
Looking forward to starting chapter 10 tomorrow!
No comments:
Post a Comment