Skip to main content

Posts

Showing posts with the label oop

How to become a better programmer

I'll be the first to admit, programming was never something I found easy. My very first experience in programming was when I got this book at the ripe age of 11. I liked playing my Nintendo 64  and wanted to make games on my own. The book that changed it all for me My ability was far under sub-par. Somewhere in these  forums I wrote a post asking for help trying to understand a while loop - needless to say I got defensive because I felt I was being talked down by people smarter than me, telling me that I should start and learn more simpler things first (than dive right into making a PC game). Forums did actually look like this (circa 2005) The truth was, I was being too ambitious. BUT - TwisterMan was not going to code itself! (All drawn in glorious Microsoft Paint :)). Animation frames of TwisterMan doing some whirlwind attack Watch out for spikeo ! *rawr* And whoever this boss was called... Baaaa? The point I'm trying to get across i...

Do you choose inheritance or interfaces?

What's the right answer? The answer to every programming question Let's explore both options and when you might choose to prefer one or the other. Pay extra special attention and focus because this is a common job question and an answer you should fundamentally know if you want to become a better software developer! Why choose interfaces? Choose inheritance when your objects have a has-a or can-do relationship. What does this mean? A has-a relationship means the object implementing the interface "has a" object/thing that is the interface. Here is a concrete example of a has-a relationship: public interface IWheel { public void TurnRight ( ) ; public void TurnLeft ( ) ; } public class Boat : IWheel { public void TurnRight ( ) { // implementation } public void TurnLeft ( ) { // implementation } } A boat has a wheel, and is an example of using an interface with a has-a relatio...