|
Wednesday, 31 January 2001 09:24 |
|
Page 1 of 4 Increasing Reusability: An Object is an Encapsulation that Shares Its Behavior There are many approaches to making software easier to reuse, but I will focus on only one of these that is particularly relevant to object-oriented programming: In software systems, it is common that certain modules, data structures, or other elements will be used over and over again, with minor modifications each time. The normal solution to this problem has been to simply copy and paste, and modify the copy to do the new task. This works if there are only a few changes to be made. But as the complexity of the changes grows, and as you start modifying a copy of a copy of a copy, bugs start creeping in faster than you can catch them. A better way to reuse these programming modules is to keep the original module intact as a kind of template to refer to, and then define new modules by listing just the changes made from the original template. Then if a function or variable hasn’t been listed in the new module, you know that it’s exactly the same as in the original. This approach is called behavior sharing because other than the changes that have been explicitly listed, the new module shares the behavior (functionality) of the original one. Since all the identical code doesn’t have to be copied from the original, behavior sharing keeps code simpler and saves a lot of time.
|
|
Last Updated on Tuesday, 28 October 2008 14:51 |