10.4 Finding Commonality in Code

 < Day Day Up > 



10.4 Finding Commonality in Code

Before reuse can occur, commonality in the program must first be identified so that it can be abstracted into a function or an object. Finding common code that is present multiple times in a program is something that is obvious to an experienced programmer but for some reason is often not recognized by the novice programmer, who can blissfully repeat the exact same code, perhaps with variable names changed, over and over again not realizing that they just finished doing the same thing two statements before in the program. Inexperienced programmers will copy blocks of code within a program and never think to abstract it into a method. How to begin to recognize that code is appearing time and time again and can be abstracted is not something that is easily taught and appears to require experience. However, it is well recognized in computer science that when common code occurs the programmer should abstract that common behavior out and create a single implementation that can be used multiple times in the program. Abstracting out this behavior could be as simple as writing a subroutine in C or as complicated as making an entire Java class.

Most computer scientists generally agree that this abstraction of common functionality is a good thing. That it does not happen often enough is also generally agreed. For some reason, programmers often seem loath to implement a prepackaged solution for their programs, instead choosing to "roll their own" solutions. Why this is true is the subject of many debates, studies, and conjecture in the computer science field and is not an appropriate topic for this book. Instead, the way that these methods can be reused are discussed here.



 < Day Day Up > 



Creating Components. Object Oriented, Concurrent, and Distributed Computing in Java
The .NET Developers Guide to Directory Services Programming
ISBN: 849314992
EAN: 2147483647
Year: 2003
Pages: 162

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