home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!root44!hrc63!mrcu!paj
- From: paj@uk.co.gec-mrc (Paul Johnson)
- Newsgroups: comp.lang.eiffel
- Subject: Re: Small methods ! Why ?
- Message-ID: <1857@snap>
- Date: 29 Jul 92 07:31:28 GMT
- References: <13303@ns-mx.uiowa.edu>
- Reply-To: paj@uk.co.gec-mrc (Paul Johnson)
- Organization: GEC-Marconi Research Centre, Great Baddow, UK
- Lines: 47
-
-
- >I came across the following sentence in a paper:
-
- >"Good object oriented programming style seems to encourage the
- >use of many small methods."
-
- >Why is this so ?
-
- One of the major goals of OO programming is flexibility. A big
- function can only be modified by delving deep into its code. The only
- way of reusing a part of its functionality is by copying the code and
- changing bits. On the other hand, lots of little functions can be
- modified by replacing one function with another. Dynamic binding
- (what C++ calls `virtual functions) provides a way of doing this in a
- controlled manner. Hence an OO program with lots of little functions
- is more flexible and hence more mainainable.
-
- >This programming style leads to code (and functionality)
- >that is widely dispersed. Therefore, a maintainer may have to
- >use sophisticated class browsers to understand the code even for
- >a fairly simple task, simply because it is widely dispersed.
-
- One of the major concepts in Eiffel is that you should not have to
- delve into the code to understand a piece of functionality. The class
- documentation (including the short-flat form with its preconditions
- and postconditions) should make this clear.
-
- If it does become necessary to delve into a function, one that has a few
- lines of code which call other functions is more understandable than a
- complex mess of loops and local variables.
-
- >This style seems to be quite prevalent among C++
- >programmers.
-
- >Is it so with programmers in other OO languages as well ?
-
- Yes. Even more so with Eiffel.
-
- Paul.
-
-
-
- --
- Paul Johnson (paj@gec-mrc.co.uk). | Tel: +44 245 73331 ext 3245
- --------------------------------------------+----------------------------------
- These ideas and others like them can be had | GEC-Marconi Research is not
- for $0.02 each from any reputable idealist. | responsible for my opinions
-