C Sharp

Object Oriented Programming

The goals of this tutorial are to guide you through the terminology of object-oriented programming (OOP) and to give you an understanding of the importance of object-oriented concepts to programming. Many languages, such as C++ and Microsoft Visual Basic, are said to "support objects," but few languages actually support all the principles that constitute object-oriented programming. C# is one of these languages: it was designed from the ground up to be a truly object-oriented, component-based language. So, to get the absolute maximum out of this tutorial, you need to have a strong grasp of the concepts presented here.

I know that conceptual tutorials like this are often skipped over by readers who want to dive into the code right away, but unless you consider yourself an "object guru," I encourage you to read this tutorial. For those of you only somewhat familiar with object-oriented programming, you should reap benefits from doing so. Also, keep in mind that the tutorials that follow this one will refer back to the terminology and concepts discussed here.

As I've said, many languages claim to be object-oriented or object-based, but few truly are. C++ isn't, because of the undeniable, uncircumventable fact that its roots are deeply embedded in the C language. Too many OOP ideals had to be sacrificed in C++ to support legacy C code. Even the Java language, as good as it is, has some limitations as an object-oriented language. Specifically, I'm referring to the fact that in Java you have primitive types and object types that are treated and behave very differently. However, the focus of this tutorial is not on comparing the faithfulness of different languages to OOP principles. Rather, this tutorial will present an objective and language-agnostic tutorial on OOP principles themselves.

Before we get started, I'd like to add that object-oriented programming is much more than a marketing phrase (although it has become that for some people), a new syntax, or a new application programming interface (API). Object-oriented programming is an entire set of concepts and ideas. It's a way of thinking about the problem being addressed by a computer program and tackling the problem in a more intuitive and therefore more productive manner.

My first job involved using the Pascal language to program the box-office reporting and itinerary applications for Holiday on Ice. As I moved on to other jobs and other applications, I programmed in PL/I and RPG III (and RPG/400). After a few more years, I started programming applications in the C language. In each of these instances, I was easily able to apply knowledge I had learned from prior experience. The learning curve for each successive language was shorter regardless of the complexity of the language I was learning. This is because until I started programming in C++, all the languages I had used were procedural languages that mainly differed only in syntax.

However, if you are new to object-oriented programming, be forewarned: prior experience with other non-object-oriented languages will not help you here! Object-oriented programming is a different way of thinking about how to design and program solutions to problems. In fact, studies have shown that people who are new to programming learn object-oriented languages much more quickly than those of us who started out in procedural languages such as BASIC, COBOL, and C. These individuals do not have to "unlearn" any procedural habits that can hamper their understanding of OOP. They are starting with a clean slate. If you've been programming in procedural languages for many years and C# is your first object-oriented language, the best advice I can give you is to keep an open mind and implement the ideas I'm presenting here before you throw up your hands and say, "I can fake this in [insert your procedural language of choice]." Anyone who's come from a procedural background to object-oriented programming has gone through this learning curve, and it's well worth it. The benefits of programming with an object-oriented language are incalculable, both in terms of writing code more efficiently and having a system that can be easily modified and extended once written. It just might not seem that way at first. However, almost 20 years of developing software (including the past 8 with object-oriented languages) have shown me that OOP concepts, when applied correctly, do in fact live up to their promise. Without further ado, let's roll up our sleeves and see what all the fuss is about.