[Tutor] Communication between classes
Alan Gauld
alan.gauld at btinternet.com
Mon Apr 2 02:20:28 CEST 2007
"Greg Perry" <gregp at liveammo.com> wrote
> That makes sense, thank you for the detailed explanation
> Andrei. For this simple project I am working on, it looks
> like the most direct route would be to use functions
Thats often the case. Often when people start with OOP
they try to do everything with objects. Its possible but often
not very efficient.
> and only develop classes for the portions of the program
> that can be reused.
> Is it safe to say that classes are only useful for instances
> where reuse is a key consideration?
Its not only for reuse. Classes and objects are often a
more natural model of the real world. One of the best
examples is a GUI program where each window or control
can be treated as an object. Thats intuitively obvious because
to our eyews it looks and acts somewhat like a real world
object. But you rarely reuse the specific controls or windows
developeed for a particular project. (Widgets are another
matter, they are designed for reuse)
> seems that classes are in most cases overkill for simple
> tasks
Yes thats true. OOP was invented as a way to control
complexity in large programs. It can be used in smaller
programs but if you only have a dozen or so linres of
executable code then classes may well be overkill.
> such as reading the command line then calculating a
> hash/checksum to verify integrity
If you had a lot of different data types each with their own
checksum algorithm then classes and objects might be
appropriate but a single case would usually be easier
using functions.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list