Wednesday, November 19, 2008

DotNot, Part 3

Previously in this series, I have covered my professional history, my past. Before I move on to an extended discussion of the present, let's sum up a couple of pertinent points concerning the past.

As a software developer primarily using COBOL, I thoroughly internalized the procedural programming model. This methodology requires an extremely straightforward, step-by-step mode of thinking. A flowchart is a very good representation of this style.

Scope is the lifetime of a data item in a program. It is also the reach of both a piece of information and executable code. In a program written in a procedural oriented program, scope encompasses the entire program.

So, to the present. The dominant software development methodology currently is object oriented programming. What, you may rightly wonder, does this mean, and how is it different from what went before?

Object oriented programming, or OOP, is a philosophy that focuses on "black box" entities rather than processes. It is a way to represent real life items, their attributes, and their behaviors in executable code. These representations, these "objects", are discrete building blocks that, when combined, form functional programs. They are also easy to reuse.

OOP is accomplished through myriad programming tools, among them the classic languages C++ and Smalltalk, as well as the contemporary Java from Sun Microsystems and Microsoft's C# and Visual Basic.Net. Each of these languages must support certain concepts: encapsulation, inheritance, polymorphism.

Encapsulation is the embodiment of a program as a black box object. The idea is that the user of an object needs to know that as long as the interface to the object is consistent, he will receive consistent data back on each use; there is no need for the user to be aware of the inner workings of the object. The interface defines what will be passed to the object and the what will be returned to the user. The how of achieving this is hidden from the user, encapsulated in the object.

Inheritance is the notion that you start with a very generic template in code. This template is called a class, and it contains your basic functionality. Now, describe a slightly more specific case, one that requires one or more small functional extensions. This more specific case requires a new class that is derived from the generic base class; the only new code is what the extensions require. Everything else is inherited from the base class. Think Car or Truck based on Vehicle. This can be extended to more and more specific cases.

Remember that a class is a template for an object; an object in turn is an instance of a class. When the program for a class is executed, an object has been instantiated.

Polymorphism means that something has multiple forms. Objects have methods, which, when invoked, do something; in fact, an object can have multiple methods with the same name. Imagine Car Starts using only a key in normal circumstances, but it Starts with a key and jumper cables when the battery is dead. Object Car has at least two Starts methods, and the one that executes depends on what parameters are passed when the method is invoked.

There's certainly more to OOP than this introduction, but take away this basic difference from the procedural model: where procedural programming is extremely straightforward, specific, and concrete, OOP is indirect and generic. Its goal is the abstraction of functionality, especially very common functions, into a library of plug-in modules that can be snapped into an application wherever they're needed, and reused as often as possible.

In OOP, the scope of both data and executable code is severely limited compared to a procedural program.

My company uses Microsoft technology in software development. Microsoft's approach to OOP is the .Net (pronounced dot net) framework, and as I've said before, OOP is a struggle for any programmer who learned and practiced procedural programming, as I did, for 15 years. That's why this series of essays has been entitled DotNot.

I learn any new concept or skill best by hands-on practice. As I do more OOP, the struggle lessens, so maybe I'll reach DotYes someday.

An addendum, wherein I whine about the .Net type system.

No comments: