Reusability of Code
Essay by Prong69 • October 1, 2013 • Essay • 502 Words (3 Pages) • 1,957 Views
Reusability of Code
The phrase "Reusability of Code" speaks to the idea that once you have written a specific piece of code to run a specific narrowed down task, you ought to be able to utilize that same exact code in other areas of the same program - or other programs entirely (with perhaps a few minor adjustments).
Within the realm of procedural programming the reuse of code within the program consists of having to copy and paste the same version of the code each time it is necessary to be used. There may need to be some alterations to the copied code to coincide with the different portion of the program needs, but the idea is that you need to basically reinvent the wheel each time you want to run that specific code. If you consider the amount of extra coding that could be necessary - you can begin to understand the gravity of the extra inefficiency that can become prevalent in procedural programming. The chance for error goes up - and the time it takes to physically program something becomes more demanding at all phases of the process.
With Object oriented programming - the reuse of code becomes far more efficient. Once a specific task has been determined needed within the program, the code for just that one task can be written and perfected. It is then that the programmer can place that code in a separate file or module to be called upon at any time by the main program. Specific information that is needing processed will be passed over to the specific module developed to handle that type of operation and the results are then passed back to the main controlling program. In this fashion, there is never a need to alter the code along the way or develop it with the possible differences that could be requested. All the different possible requests are processed and regurgitated between the different objects. Having code written to handle a specific task also allows a programmer the ability to take that module and apply it into any number of different programs that might require a similar need accomplished. There is little need to reinvent the wheel if you are using this type of programming along with proven coding.
Within procedural programming - data passing is done directly with the program from each function or argument to the next. With object oriented programming, the data is encapsulated between the different objects and is considered "hidden" from the other objects. The security within the Object Oriented programming is inherent because code is not exposed in a top-down method like it is within procedural programming. Each object has a specific task and traits are inherited from parent objects. With each object or module having a specific task to perform, nothing is left open to be viewed at each step. Information is passed into the object and the results are passed back. Within procedural programming, you can see exactly all the steps performed along
...
...