8.2 Objects and Built-in Objects
So far, we have been writing code that is procedural in nature; that is, code whose logical flow starts at the top and works its way to the bottom. Any computer program can be written in a procedural manner. However, when code gets long, it becomes difficult to debug and maintain. It also becomes redundant and dangerous to write the same code over and over. The object-oriented approach was created for dealing with these very issues. To switch to objects, you must understand why they are useful in the first place.
Imagine a product as complex as Microsoft Word. To produce it, a team of Microsoft programmers had to write millions of lines of code, with hundreds of people working on the code at the same time. To support simultaneous development, the code was segmented by functionality. Understanding how such complex products get subdivided into manageable pieces requires that we first understand the building blocks of such code. These building blocks in Ruby are classes that define objects.
8.2.1 Objects
Objects and object-oriented programming simplify the implementation of large programs. If you work on a program by yourself, it is up to you to organize your work. If you work with 100 other programmers, then everything must be nicely compartmentalized; otherwise, each programmer will constantly step on the other programmers’ toes. There is nothing worse than getting your piece of a program to work and finding out that you inadvertently broke ...
Get Computer Science Programming Basics in Ruby now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.