Showing posts with label Learning. Show all posts
Showing posts with label Learning. Show all posts

Sunday, February 7, 2016

if (catchyTitle.Text == "Interface Inheritance" ) { MessageBox.Show("Chapter 7 is done!") }

This chapter took a little longer than prior chapters. Maybe it is because there is more material and the coding projects try to use the majority of code I have learned in the prior chapters. So, since a few blogs ago I decided that I wasn't going to use the "help" as much as I had been prior. I would say I succeeded pretty well in this chapter. Building a house with places to hide I did go to solution after I got stuck and was unable to make progress. I hope it helped me learn what I was actually using better. I think it also helped that I didn't have many days between actually looking at code I started and code I was finishing. Instead of having to remind myself of what I did before, I was able to remember it pretty well.

While my code doesn't look the same as the solution, and probably has more lines then what is needed, I ended up having an issue where my form wasn't updating correctly. The issue showed itself after I implemented the interface for a hiding place. I forgot to call a method when moving from one room to another called ReDreawForm(). Hence, the form was not redrawing and giving incorrect information about where the hiding place was in the different rooms.

Well, the hide and seek project (I called it long project because when I started it the book said it was going to be a long one) contains both outside rooms and inside rooms. Both inherit from the Room class. Then there are two interfaces for rooms that have exterior doors and rooms with hiding places. I had to do some searching on what to display depending on the room type (IHasExteriorDoor or IHidingPlace). In comes upcasting and downcasting (aka Polymorphism). Example of finding a class that inherits from an interface:

if (currentLocation is IHasExteriorDoor)
            {
                goThroughTheDoor.Visible = true;
            }

That brings me to another point, Object Oriented Programming has four principles (why the book waited to chapter 7 is a good question):
  • Inheritance - one class or interface inherits from another
  • Encapsulation - creating an object that keeps track of its state internally using private fields, and uses public properties and methods to let other classes work with only the part of the internal data that they need to see
  • Abstraction - When you create a class model that starts with more general - or abstract - classes and then has more specific classes that inherit from it. Cannot instantiate these
  • Polymorphism - "Many forms" Take an instance of one class and use it in a statement or method that expects a different type, like a parent class or an interface that the class implements. Upcasting or downcasting allows us to get polymorthism.

We have used all of the principles so far, it now is a matter of being able to remember each principle and how each is used (so much to remember, but I think coding more often will help that). 

This chapter also talked about access modifiers. You know, like public or private but with a few more. 
  • Public - anything can access this (as long as access to the declaring class.) Least restrictive. Only use if you have a reason to make it public.
  • Private - only other members in the class can access it (other instances of the class can use these as well). You can only mare a class private if it is encased in another class.
  • Protected - public to subclasses, private to all else.
  • Internal - public only to other classes in the assembly. Protected Internal can only be accessed from within the assembly OR from a subclass.
  • Sealed - class which cannot be subclassed. Not an actual access modified, it only affects inheritance.

I think something to help remember the implementations, inheritance from a class allows you to modify the methods or use the methods how they are written in the base class. Interfaces have abstract methods and cannot be instantiated. The methods in the interface do not have any code in the contained methods, it only tells a class that inherited from the interface that all the methods MUST be used. The class can then implement any type of code needed for the given method, but it has a framework of what needs to be implemented from the interfaces.

I am only touching the surface I know. So much to learn!

Thursday, February 4, 2016

The Communities we belong to...

We are given time to innovate each week and sometimes I do it and sometimes I don't. I really need to get better at not only spending innovation time innovating, but also what I am innovating on. Well, we had a really interesting and fun experience at work yesterday. We were able to participate in Open Space (more information at http://openspaceworld.org/). We weren't given much information as to what the day would entail or what would be expected of us. At the beginning we discussed passion and that maybe Open Space would help Innovation Time to get some real quantifiable results (sometimes the innovation projects got lost and nothing comes of them). We were given 45 minutes blocks to bring up topics we felt passionate about. I brought up C# learning. I didn't expect many people to come to this session.

When the session started in the afternoon, I was surprised at how many people came to talk about C# learning. It makes sense, another team is going to start using C# more and wanted to see what I, a person on engineering using C# everyday, was doing to help in my learning. Our discussion led us to what I was using and how we could all learn what resources and communities others were using in order to stay on top of their coding.

I thought that I had a limited number of resources I used...but then I really looked at the sources I am using. Between blogs, people I follow on Twitter, and my network at work I actually do have quite a few resources. Of course there is the obvious one, I use the book resource that leads to most of my blogs. I feel it is a great resource, I get in-depth training on the basics of C# and I (hopefully) provide what I learn in a blog. 

At work I obviously have my co-workers that I can work with and ask questions of. One, K.C., appeared to take particular interest in me and I ask many questions of him. You could say he is acting as a mentor to me. Strange thing, I have never asked someone to mentor me that is younger than me. I am getting old, but then I guess that happens when you switch careers.

Then I follow other coders on Twitter and try to read their blogs (at least when I don't think that the subject will be a mile over my head). I like getting their perspectives and I hope that the bits of information I get from reading their blogs and posts will help in my learning. I follow (to name a few) Scott Hanselman, Troy Hunt, Jeff Atwood, John Papa, Visual Studio and those are just a few of those I feel can add to my learnings. Hey, maybe one day I will post a question in Twitter and receive a response from those I follow or that follow me.

I was lucky one day and found a retweet from one of those I follow about CodeNewbie (funny that I picked Newbie Programmer). CodeNewbie is a set of blogs, podcasts, Twitter discussions, and probably more that I haven't found out about yet. From listening to the podcast I have already found a couple great communities to use in my code adventure. Some of the stories are similar to mine, 30 somethings that switch careers and trying to learn to code. I hope to take part in the weekly discussions that are held on Wednesday nights and that I will be able to contribute my knowledge gained.

There are more like Free Code Camp (I just started following them and need to check it out more), Evasium Programmers (need to look more into this one too) and the usual Microsoft accounts to help in all things Microsoft. I know my world will keep expanding too.

So, I have a few communities I use to learn, and it continues to grow as I dive deeper into coding. In the Open Space meeting where we talked about what everyone uses, I am not aware of anything used at work for one person to pass along the resource and communities one person belongs to those that are trying to learn C#. Maybe I should start a Slack channel at work, or is there a better way to pass this knowledge on? I need to let others know what I am reading and who I am following. They may prove useful to someone else just starting to learn to code.

What communities have you found to belong to?

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!