It is funny, I was chatting to somebody yesterday. The subject was the specialist skills that she had gained during her education, and subsequent working life. Well, they seemed specialist to me – I do my best to follow but sometimes it is difficult to keep up.
We finished the conversation with me saying that I would need to talk about my own “specialist” skills one day, so maybe today is the day to start?
In my first job, I did some computer programming. When I started, it was just making small tweaks to programs written by other people. The program would do this, then this, then this, then this, etc. All very much like an ordered list, if you have ever come across them. (WordPress lets you create ordered lists in your posts.) I later learned that this type of programming had a name – procedural programming. Because it was a procedure. Do A, then B, then C etc. One thing after another.
I was still quite a novice in this environment when I was asked to get involved in another type of project. The first one had been quite an advanced simulation – lots of physics coming into play. Very theoretical. The next project was far more practical – controlling things. Move something six inches along a track, by way of a computer program.
In fact, I had been dropped into an object-oriented (O-O) environment, though at that stage I didn’t appreciate what object-orientation was. More about object-orientation in a moment.
That first object-oriented project was a challenge, because I was trying to apply my A, B, C knowledge to an environment which didn’t really fit. These days, I look back and cringe. I guess most of us do when we think about the messes we created at the very start of our careers! Retrospectively, I was probably in the best environment possible, simply because I was given the time and space to learn and to actually become very good at object-oriented development, but at the time, the learning curve was very steep.
So, what exactly is object-oriented programming? Well, actually, it is a deceptively simple approach. You see things as a set of “objects” which interact with each other, to get the job done. Just like in the world outside our windows. Objects? Well, imagine a car, say. A car is an object. Anything can be an object. Within our idea of a “car” we can say a few things. The car contains four other objects, called wheels, plus another object, called an engine, one called a steering wheel, and so on. And you can do things to it, like “drive” it, or “stop” it. All real-life things. So, easy to visualise how something hangs together.
So, you have your world full of these objects. And each object does it’s own special job. If I were to get into a car, and drive off in it, to be honest I have no idea how it gets anywhere. What happens under the hood, I leave that to a mechanic. If it won’t go, I am stuffed – I leave that to a machanic.
And it is exactly the samewith onject-oriented programming. The “car” does not know how it moves, but it has an engine, and that does! In the same way, the engine can hide all the mucky bits away – the oil, the petrol, the spark plugs etc. All the car needs to know is how to drive the thing! In the world of O-O, we call this encapsulation.
Then, you look up and down the scale, not just at the car. Looking in more detail, we can see a wheel, which has tyres and so on. And, looking instead at the bigger picture, what exactly is a car? It is a motor vehicle. An engine, four wheels, a steering wheel….. Just like a bus or a truck. They all get us from A to B. Okay, they’re all a bit different from each other, but there’s a lot in common. Just recognising these similarities, we call specialization, or inheritance.
In fact you can go even further up and recognise that these motor vehicles are themselves just special cases of a vehicle, which might include a pushbike, say. Or, think of a motor bike – just two wheels, but still a motor vehicle. So do you see a kind-of tree forming? Where everything fits snugly into its place? At the trunk you’re very general, but your description covers many things, whereas as you proceed out to the tips of the branches, you gradually split off and become more and more specialised.
And that’s really 90% of the way there!
But you can imagine these trees can become quite complex. You can imagine, with a car, you’re talking about thousands of objects, from the tiniest nut or bolt, to somethind like the chassis. And that was my job, though not with cars – to look at a particular problem and work out what the tree looked like. It was one of those things, I got into it because I was good at it, at seeing similarities, at pinpointing differences, but believe me, a lot of people just don’t see the world in this way.
Shall I try to push it just a little bit further? You drive a car. You drive a bus. You drive a truck. What’s the difference? Okay, there’s a small difference in each, but fundamentally, you’re putting your foot on the gas, and <whatever you’re driving> goes from A to B. So, in fact, the act of driving the vehicle is pretty much the same in each case. We have a name for that too – the most complicated name of the day, because it comes from Greek. We call it polymorphism, which literally means many forms. But don’t worry, I’m not going to test you on any of this!
But would you like a little homework? Look again at my featured image, and tell me what’s wrong with it 🙂.