<?xml version="1.0" encoding="windows-1252"?>
<node id="91080" title="Damian Conway's ten rules for when to use OO" created="2001-06-24 17:19:07" updated="2005-08-15 01:43:40">
<type id="120">
perlmeditation</type>
<author id="72812">
petdance</author>
<data>
<field name="doctext">
 &lt;P&gt;On Saturday, June 23rd, 
[http://www.conway.org|Damian Conway] had a little free-for-all workshop that
he gave at 
College of DuPage in Wheaton, IL.
Although [91105|the whole day was fascinating], the most
useful part for me was his discussion of ``Ten criteria for knowing when
to use object-oriented design''.  Apparently, Damian was once a member
of Spinal Tap, because his list goes to eleven.&lt;/P&gt;
&lt;P&gt;Damian said that this list, in expanded form, is going to be part of the
standard Perl distribution soon.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;Design is large, or is likely to become large&lt;/STRONG&gt;&lt;BR&gt;

&lt;LI&gt;&lt;STRONG&gt;When data is aggregated into obvious structures, especially if there's a lot of data in each aggregate&lt;/STRONG&gt;&lt;BR&gt;

For instance, an IP address is not a good candidate: There's only
4 bytes of information related to an IP address.  An immigrant going
through customs has a lot of data related to him, such as name, country
of origin,  luggage carried, destination, etc.
&lt;LI&gt;&lt;STRONG&gt;When types of data form a natural hierarchy that lets us use
inheritance.&lt;/STRONG&gt;&lt;BR&gt;

Inheritance is one of the most powerful feature of OO, and the ability
to use it is a flag.
&lt;LI&gt;&lt;STRONG&gt;When operations on data varies on data type&lt;/STRONG&gt;&lt;BR&gt;

GIFs and JPGs might have their cropping done differently, even though
they're both graphics.
&lt;LI&gt;&lt;STRONG&gt;When it's likely you'll have to add data types later&lt;/STRONG&gt;&lt;BR&gt;

OO gives you the room to expand in the future.
&lt;LI&gt;&lt;STRONG&gt;When interactions between data is best shown by operators&lt;/STRONG&gt;&lt;BR&gt;

Some relations are best shown by using operators, which can be overloaded.
&lt;LI&gt;&lt;STRONG&gt;When implementation of components is likely to change, especially in the same program&lt;/STRONG&gt;&lt;BR&gt;

&lt;LI&gt;&lt;STRONG&gt;When the system design is already object-oriented&lt;/STRONG&gt;&lt;BR&gt;

&lt;LI&gt;&lt;STRONG&gt;When huge numbers of clients use your code&lt;/STRONG&gt;&lt;BR&gt;

If your code will be distributed to others who will use it, a standard interface
will make maintenence and safety easier.
&lt;LI&gt;&lt;STRONG&gt;When you have a piece of data on which many different operations
are applied&lt;/STRONG&gt;&lt;BR&gt;

Graphics images, for instance, might be blurred, cropped, rotated, and adjusted.
&lt;LI&gt;&lt;STRONG&gt;When the kinds of operations have standard names (check, process, etc)&lt;/STRONG&gt;&lt;BR&gt;

Objects allow you to have a &lt;CODE&gt;DB::check&lt;/CODE&gt;, &lt;CODE&gt;ISBN::check&lt;/CODE&gt;, &lt;CODE&gt;Shape::check&lt;/CODE&gt;, etc
without having conflicts between the types of check.
&lt;P&gt;&lt;/P&gt;&lt;/OL&gt;

</field>
</data>
</node>
