Learning questions


#1

Hi. I program a fair amount in my everyday job, but it’s essentially BASIC. This is my first foray into OOP. I’ve been following along pretty well up until this chapter. I generally know what is happening, but it’s so much new information at once that I’m getting bogged down. Frankly I’m not sure how to proceed in the book. I’m attending the iOS bootcamp in january, so my goal is to get all the way through this book before I go. What I’m struggling with is figuring out to what degree I need to intimately understand what I’m plowing through. If anyone has any thoughts or advice, I’d be happy to hear it.

Here’s a particular example of how I’m getting stuck…

I’m working on the Challenge, and frankly I’m having to do a good bit of cheating by looking at other people’s code from this forum. But I a trying to make a real effort to understand what is going on.

Here’s a line in particular that I “get but don’t get” if that makes any sense.

In my Portfolio.h file…
-(void)addStock:(StockHolding *)stock;

I understand that I am having to declare a method that my portfolio object(s) will use. I understand that this particular method is the method by which the main() program will add a stock into the portfolio array. It looks like ‘stock’ is the stock object that will be added and (StockHolding *) is the class of object that ‘stock’ is.

But here’s my problem…if I were sitting here at my machine writing this program on a blank slate, I would have no clue how to construct that line on my own. I would know that I need a method to add a stock object to my portfolio array but I would only get about as far as -(void)addStock. I might know that I have to specify an object name such as ‘stock’ and that I somehow need to mention that the ‘stock’ object is a StockHolding object, but I wouldn’t know how to write the line and I wouldn’t know exactly where in the book to refer back to. So…my question is really this I guess: How does a newbie best figure that out? Is there somewhere to look that has say, “examples of implementation methods”?

Hmmm…that seems to make little sense now that I read back over it. The answer may very we’ll be this: “I need to go back several chapters and re-read several times”. Fair enough. But I would like to plow on too.

Thoughts?


#2

So, there are two questions here:

  1. “I want to learn, this isn’t easy, I’m coming to the ranch soon. What should I do?” You are doing it. Keep plowing through. When you reach the end of the book, go back and review things that are still confusing. It is OK that it isn’t easy – it will be one day. You’ll learn a truckload when you come to the ranch, but whatever preparation you can do beforehand will make it more pleasant.

  2. “-(void)addStock:(StockHolding *)stock; Huh?” Well, you pretty much answered it. This is how your Portfolio class advertises “Hey! I’ve got an addStock: method!” When the compiler is working on main.m, it will use that advertisement to understand a line like:

Cool?

I’ll look forward to meeting you when you come to the ranch!


#3

Thanks for the response. Much appreciated.

  1. Yep, that answers me just fine.
  2. Well…my question is really, “Is there any kind of examples list compiled anywhere that gives of various kinds of method declarations?” When it was time for me to come up with this line of code, I knew conceptually what I needed to do but no idea how to do it or where exactly to look.

Thanks!