Real-Life Objects and Object-Oriented Programming


For decades, programmers have undertaken the enormous job of writing computer programs that automate the way business is conducted . In the olden days, as some programmers might say, a program consisted of one long series of step-by-step instructions that directed the computer to do something. Typically programs were used to automate a business process such as processing an order, which is the same thing that programs do today.

Once the automation fever caught on, businesses demanded that programs take over many business operations. Programs grew in size and complexity and soon became unmanageable, expensive, and time consuming to maintain.

Procedural programming came to rescue programmers. Procedural programming organizes instructions into groups that perform one task, called a procedure . Procedures are referred to as functions or methods in some programming languages. Think of a procedure as instructions used to enter a new order, display an existing order, or perform any task.

Procedural programming simplified programming by making it easy for a programmer to quickly sift through hundreds of lines of instructions to locate a procedure that needed to be upgraded.

In addition, procedural programming provided another benefit that made a programmers life more bearable. Procedures, written in a programming language such as C, can be reused in other programs that require the same procedures. Programmers refer to this as reusable code .

Heres how reusable code works: Lets say that a programmer writes a procedure in an order-processing program that matches a ZIP code with a city and state. This enables a sales representative to enter a customers ZIP code and then let the computer look up the city and state associated with the ZIP code.

You can imagine that many programs within a company have the same need. Rather than rewrite the ZIP code procedure for each of those programs, a programmer can use the same ZIP code procedure in those programs. This saves time and money, and it produces reliable programs because the ZIP code procedure is already thoroughly tested .

Procedural programming revolutionized how programs were written, but there was another problem that still needed to be addressed. The real world, which a program mimics, is organized into objects, and not procedures. An object consists of attributes and behaviors, as you know.

Each time a new program was written, the programmer had the challenge of re-creating an object-oriented world using a procedural programming language. It was like trying to slip an octagonal peg into a round hole. The peg fits with a little coaxing, but its never a perfect fit.

The problem was solved with the introduction of object-oriented programming in the 1980s. Object-oriented programming uses an object-oriented programming language such as C++ or Java to mimic real-world objects in a program by defining a class. A class is composed of data members and member methods. Data members are sometimes referred to as fields and are used to store attributes of an object. Member methods are sometimes referred to as member functions and define an objects behavior. Youll learn much more about classes throughout chapters of this book.




OOP Demystified
OOP Demystified
ISBN: 0072253630
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net