In my many years of software development, time and time again I find myself trying to explain some strange pattern or concept to an unwanting victim. Typically I try prodding for the skill level of the individual to adjust my vocabulary and technical details.
Sometimes… I just blurt out all kinds of random techno-weenie bullshit.
Then there comes this sweet, motivated young woman who wants to learn how to develop. She’s very very very green to writing code, yet shows “somethin’ fierce” when it comes to wanting to learn. Unfortunately her company won’t spend the time or money to give her the resources to learn… and she’ll be expected to jump in on projects very shortly. Jake and Mike to the rescue.
Typically.. if people want to learn to write code, I always hear the question… “How do I do this? How do I do that?” That’s not necessarily bad, but not the best place to start either.
The concept of a human telling a computer to do something is not trivial. People do it everyday on a different level. I think people can easily step back and think about the actual core concept of writing software: using some language to tell the computer what to do. The gap comes from what happens in the middle.
To help close this gap, I took it upon myself to bring Melanie into the world of Object Oriented Design (or whatever your current flavor is). She understands what writing code means and she was told that there were “classes” to look at. Here came the biggest question and probably one of the most pinnacle question, “What is a class?”
Here’s where I came up with an example. Disclaimer: I know that this example may/may not be the best. There’s arguments either way… but it got the job done. Plus it’s Holiday themed.
One important step in learning OOP is knowing what the difference and definitions of a class and instance are. It’s a core concept, but once you understand it… it makes sense.
Here’s how I described it. Imagine you have a snowman shaped cookie cutter. To blatantly put it, the cookie cutter is analogous to a class. The cookie cutter has properties that define what the cookie cutter does and it shows behaviors that a cookie cutter can do. Now an instance, is a manifestation of the class, therefore a cookie would be the example of a class. It behaves like the cookie cutter defines it, it has properties that are defined by the class, and it is unique. It’s state can be changed.
The cookie cutter has the property that it’s initially shaped like a snowman. The cookie instance has a shape property that initially starts off being a snowman, but since it’s unique and an instance, it can change it’s shape, without affecting any other cookie instance. If I want to cut off the snowman cookie’s head, I can. The rest of the cookies are still fine. If I want to put sprinkles on one of the other cookie instances, I can.. and the sprinkles won’t be on the other cookie instances.
Simple enough? I think so… Now bringing it to code just took a simple little chunk. p.s. this is where the example sort of takes a dive. We won’t bother with dealing with the confusion. It will naturally work itself out after you practice.
///
/// Defines a class to create a cookie.
///
public class CookieCutter
{
#region Fields
private string _shape;
#endregion
#region Constructor
///
/// Constructor to initialize the shape.
///
public CookieCutter(string shape)
{
_shape = shape;
}
#endregion
#region Properties
///
/// Gets or sets the shape definition.
///
public string Shape
{
get { return this._shape; }
set { this._shape = value; }
}
#endregion
}
and there you have it… your introduction to Object Oriented Design
My next advice to her was to create a set of very small goals and work to writing code that achieves them; at the same time, using examples from her life and things that she’s interested in, like illegitimate children (which her son IS legitimate…) and sexing chickens.
Talk to you soon!
Glad I could help out :: tips hat ::