From: robison1@husc10.harvard.edu (Keith Robison)
Newsgroups: bionet.software
Subject: Re: Object oriented programming
Date: 19 Aug 92 21:46:42 GMT
Distribution: bionet

wmelchior@NTBTOX.NCTR.FDA.GOV ("Bill Melchior, NCTR/FDA") writes:

>Last week there was a thread on OOP -- object oriented programming.

>I like to try to keep up with what's going on even though I'm not a
>programmer.  For folks like me, could someone who knows something
>about the field make a stab at a brief, simple definition of 
>"object oriented programming"?  I'd like to know what it is, not
>what language (C++, ?) is used; or maybe it's defined by what it is NOT?
>  
>Thanks.
>________________________________________________________________________________
>The opinions stated are mine, not those of NCTR or its sponsoring organizations.
>  
>Bill Melchior                                ||   "You have lawyers the way

	If you are familiar with structured programming, then
object-oriented programming is a logical extension of those ideas.
In structured programming, you break your program into a hierarchy
of units.  Some variables and functions exist at the top level
(globals), but others exist at lower levels.  A program becomes a
tree of nodes, with each node containing variables and functions.
Code at one level of the tree may access only those resources
(variables and functions) which are at the same node or a node
higher up the tree or on the same branch.  By organizing your
code into such a hierarchy and imposing such containment, 
opportunities for conflicts are reduced, much as compartmentalization
of a cell into organelles prevents conflicts between different
metabolic pathways.
	Object-oriented programming extends this compartmentalization
in an important way.  You can define "objects", which are logical
groups of related code revolving around a concept.  Objects have
"methods", ways of using or changing the object.  Furthermore,
some methods are "private" and can be used only within the class,
and others "public" and usable by any code.  This level of 
compartmentalization not only prevents conflicts, but it means that
the internal workings of a class can be decoupled from it's external
appearance.  That means that existing classes can be modified without
breaking old code which depends on them, so long as their external
behavior remains the same.
	The kicker in object-oriented languages is that one class
can inherit the properties of another class.  For example, I have
a Biosequence class which implements common operations for DNA
and Protein sequences.  However, there are operations specific to
each class, and so I do not directly use the Biosequence class but
instead use its properties to build DNASequence and ProteinSequence
classes.  The advantage of the inheritance mechanism is that whenever
I add a new method to Biosequence, it is immediately available to the
DNASequence and ProteinSequence classes.
	One other feature of object-oriented languages is 
overloading.  In most languages, the user can define only a
single set of parameters for any function.  However, most languages
have functions which have multiple possible parameter types.
The obvious examples are + - * /, which can generally be used
with any pair of operands (integers, reals, etc).  However, if
I define a new type in Pascal or C, I cannot define a meaning
for '+' for that type.  In object-oriented languages, you can
assign as many meanings to a function as you desire (hopefully
limited to common sense).  So, I might define '=' for my Biosequence
class to mean exactly the same sequence and length, '+' to 
catenate two sequences, etc.  


	I'm no expert on the subject, but hopefully this will provide
a quick review (and hopefully it contains no glaring errors).  If you
wish to see some actual C++ code for molecular biological purposes,
its in directory ftp/pub/contrib/kertools at golgi.harvard.edu.  
The two files are bio.h and bio.cc, but you will need ker.cc and
ker.h to compile/read them.


Keith Robison
Harvard University
Department of Genetics / HHMI
Department of Cellular and Developmental Biology

robison@ribo.harvard.edu 
Newsgroups: bionet.software