|
** Reply to note from PaulMmn <PaulMmn@ix.netcom.com> Sun, 22 Feb 1998 00:35:29 -0500 > > re: OO versus Procedural coding... > > I get the feeling that no one who does OO code believes that Procedural > Programmers re-use -any- code at all! Not so! Of course procedural programmers re-use code! But the issue is that until you have worked with a language which is _designed_ for re-using code the way an OO language is you just don't know how much of a difference it can make. > Consider the Tea Machine: > > If I had previously programmed a Coffee Machine, I would most likely have > routines (not necessarily coded as a subroutine or a separate program, but > identifiable as "This section of code determines if the user wants cream," > and "This section dumps cream into the container") that could be re-used as > part of a Tea Machine. > > If I had no inkling that I would need both Coffee and Tea machines, I might > not have coded things as subroutines or separate programs. However, I > would quickly recognize that (1) serving Coffee and Tea are basically the > same activities, and (2) it would be well worth the overhead to smash the > Coffee Machine Program into a number of sub-programs (linkage overhead be > damned!) so that both Coffee and Tea programs would call the same > sub-program for "Add Cream." > > It's how I think and code: "A nifty piece of code is a thing of beauty and > a joy forever." > > True, the inheritance is not automatic, and I have to link things together > by hand, but how automatic is linking things in the OO world? You can > point and click, but you still have to build the initial 'Beverage Machine' > before you can make a 'Tea' or 'Coffee' machine... Yes! Now, don't confuse Object Based development with OO development. An object based visual environment is really nice for building programs out of objects, but that really has nothing to do with being object oriented. An OO language can be coded strictly from a text editor but still is many times faster than coding procedural code (as you have pointed out above). The best of both worlds is to use an OO language and an object based visual developer. Believe it or not, development can be 100 times as fast as when coding procedural code via text editor. Take our beverage machine. Yup, you build the beverage machine first, then a sub class of tea machine. Later, you sub class beverage machine to coffee machine, and maybe to lemonade machine. Each time you ONLY code the methods you need to override. ALL other coding is automatically inherited. The beverage machine has a cream button, which is a subclass of button. So, another subclass is sugar button and another is lemon button. When you designed the first button, you defined all the things a button was going to do and added an interface for the method which will include button specific action. You never, never look at that code again. For each specific button, you just add the method to complete the interface. > > --Paul E Musselman > PaulMmn@ix.netcom.com Another beauty is polymorphism. Think of it! If you do a call parm in RPG, and add that call to thirty programs, then on thirty one through fifty you realize you are doing the same function, but with a different variable type you can: Use a different called program, Extend the plist and add code in the called program to check for whether or not the extended plist is being passed, Extend the plist and modify the original program, etc. etc. In OO languages, you just write the method that matches the new message options! The method that matches the message being sent is the one which gets run! This is equivelant to you writing several programs all named "Sales Tax" and calling them from different programs, some passing dollar amount, some passing dollar amount and tax percent, and some passing dollar amount and state sold in. And the system picking out and running the right program for you each time. So as you further refine your beverage machine to allow for sugar(), sugar(lumps, qty), sugar(spoons, qty) etc. you need not mess with working methods, simply build on a new one to suit your new requirement and leave alone the existing working code!!!!!!!! Gotta luv it. Chris Rehm Mr.AS400@ibm.net How often can you afford to be unexpectedly out of business? Get an AS/400. +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to "MIDRANGE-L@midrange.com". | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.