Thursday, January 14, 2016

Bee Management

Well, it is another week and I find myself saying, "I am not moving as fast as I would like." There is always more learning to be done. The amount of learning for me to feel comfortable telling people I am a developer is a large amount! Luckily, my job title is only doing part time coding, but that doesn't mean I should go slow on my learning.

This chapter took me longer than I had hoped. Not only did it take a long time, I also feel I did myself a small disservice in this chapter. The book provides the code that they want you to write. That is great when you are stuck, but I feel I was using the "help" too much. I created a Bee Management system in two parts. The first part used code that I should already know, I do. The problem, I should have taken the opportunity to learn it better. I felt I didn't have enough time to do this though and looked at the "help" more than I ought to have. I need to slow down and spend more time doing the code myself. That is a New Years resolution 14 days late.

Now, house cleaning out of the was and the confession of my sins is done. I already blogged about the inheritance in chapter 6 and, as I thought, I redid the party planner and used inheritance instead of writing extra code. Before doing that I learned a little about the hierarchy used in the code. If you don't override you can run into some issues with code not doing what you want when using inheritance.


The bee management program was done in two steps. First just writing the program that assigns the jobs to the bees, no inheritance used. The next piece was to use inheritance by adding a class that all bees used for honey consumption. Hey! I got to override the honey consumption for the queen, she apparently is real hungry when the bees work.

Not only did I override a method, I also added parameters to a subclass. This requires a little different syntax then the virtual/override. The bee class (base class) has a weight parameter and the worker bee (subclass) also tells you what jobs they can do. Do something like:

public Worker(string[] jobsICanDo, int weight) : base(weight)
(the string is an array and I hard coded the jobs a bee can do in the Form1.cs file.)

The Bee class has the weight parameter and the worker class added the jobs parameter.

So much you can do with code!

Here is the bee management program. Happy bee management!

Now that 15 days of the year have gone, I hope you are still doing your resolutions. If not, I hope you have a great new start with your old habits!

No comments: