mingIt was way back in the 1970s when Kernighan and Ritchie were working on creating a new programming language they would soon call C. It was called this because a language called B preceded it. C was created with simplicity and flexibility in mind. Its primary use was for writing operating systems, however it became popular for a wide variety of other programs. The one thing that C lacked was support for objects; it was a procedural-oriented program.
In a procedural-based programming language, a programmer writes out instructions that are followed by a computer from start to finish. This kind of programming had its advantages, but an object-oriented language makes programming clearer and easier to understand. Object-oriented software is all about using objects. An object actually contains code (member functions) and data (data members). Traditionally, code and data have been kept apart. For example, in the C language, units of code are called functions, while units of data are called structures. Functions and structures are not formally connected in C. A C function can operate on more than one type of structure, and more than one function can operate on the same structure.
In object-oriented programming, code and data are merged into a single indivisible thing — an object. This has some big advantages. A primary rule of object-oriented programming is this: as the user of an object, you should never need to peek inside the box. The way objects work are that a message is sent in and the object knows how to handle it. Thus the user never needs to see the implementation details. By not knowing what is going on inside an object, the user is unable to change the internal implementation code. Providing access to an object only through its messages, while keeping the details private is called encapsulation.
The benefits of objects do not stop with encapsulation. Objects also have the special ability to inherit functionality from other objects. When thinking about inheritance and objects, it is useful to distinguish between an is a relationship and a has a relationship because objects can have both types of relationship with each other. If the relationship between class 1 and class 2 can be said, as class 1 is a class 2, then class 2 can derive from class one. If class 2 has a class 1 you use composition to put a class 1 object into class 2 as a data member. So, one may ask, What is the benefit of inheritance? Well, with inheritance, if you find that someone has already developed an object that is mostly what you need, you can easily add new features without breaking the old ones. In other words, inheritance allows you to easily reuse code.
The last aspect of object-oriented programming is polymorphism. Objects are smart enough to be dynamic. Specifically, they have the ability to react differently depending on the situation. Well using polymorphism, an object can be made to handle any scenario with the exact same method name. Thus, depending on what the object is asked to print, it will be able to print it. Polymorphism refers to the ability of an object to have numerous methods with the same name. This is also referred to as method overloading. An object can have multiple methods with the same name but different parameter lists. The appropriate method to execute is chosen at run-time depending on which parameter list is provided in the method call. Instead of having separate methods like printPicture(), printLetters(), and printNumbers() you have one unified print() and the object itself determines how to handle the different types of situations.
Perhaps the most serious limitation of procedural programming is the tendency for large procedural-based programs to turn into spaghetti-code. Spaghetti code is code that has been modified so many times that the logical flow shown in the figures above becomes so convoluted that any new programmer coming onto the project needs a two month prep-course in order to even begin to understand the software innards. Thus, an object-oriented approach is taken to limit this so called spaghetti-code. In object-oriented programming, you build small, self-contained bits of code, which correspond more closely to how you think about your program. Thus object-oriented programming offers a new and powerful model for writing computer software due to objects, which send and receive messages. This approach speeds the development of new programs, and, if properly used, improves the maintenance, reusability, and modifiability of software.
Procedural-oriented programming is actually very powerful; so don’t let the hype make you think that it has no place in your arsenal of programming tools. A well-written procedural-oriented program can actually be easy to understand. It is just that well written procedural code is hard to find, especially when ‘teams’ of programmers, working on multiple versions are involved. The fact is that procedural languages typically lack the ability to enforce abstraction.
Computers and Internet Essays