Practices
  Home arrow Practices arrow Page 2 - Finishing the System`s Outlines
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PRACTICES

Finishing the System`s Outlines
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-05-22

    Table of Contents:
  • Finishing the System`s Outlines
  • Abstracting
  • Not Just a String
  • Constant Avoidance
  • Prototypes Are Worth a Thousand Words

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Finishing the System`s Outlines - Abstracting


    (Page 2 of 5 )

     

    In creating a description of a use case or a model of a possible class, avoid using primitive data types. Pretend that ints or doubles do not exist. Almost every type of number can be described with an abstract data type (ADT). Items are priced in Dollars (or CurrencyUnits, if you are globally oriented). The number of physical copies of an item in an inventory is a Count. The discount that a good customer receives is denoted with a Percentage. The size of a CDDisc is expressed as a Length (or LengthInMeters or LengthInInches if you are going to be sending a satellite into space). The time for a single song on a CDRelease could be stored in a TimePeriod.

    Using an ADT places the focus on what can be done with the type, not on how the type is represented. An ADT shows what you intend to do with the variable. You can declare the variable as a primitive data type and name the variable to reflect that intent. However, a variable declared as an abstract data type can have built-in validation, whereas a variable declared as a primitive cannot.

    Each ADT needs a related description. For example, a Count represents a number of items. A Count can be zero or positive. If a Count is negative, it represents an invalid count. Declaring a variable as a Count conveys this information. You can create variations of Count. You may have a CountWithLimit data type with a maximum count that, if exceeded, would signal an error.

    You can place limits on many different data types. For example, Ages (of humans) can range between 0 and 150 years, SpeedLimits (for automobiles) between 5 and 80 mph, and Elevations (for normal flying) between 0 and 60,000 feet.* All these types can be represented by an int or a double, but that is an implementation issue, not an abstraction issue.

    Abstract types can contain more than just validation. A price can be represented in Dollars. The string representation of a Dollar differs from the string representation of a double. A string for Dollar has at least a currency symbol and perhaps some thousands separators (e.g., commas). Multiplying a Dollar by a number can result in a Dollar with cents, but not fractions of a cent. Here is a possible Dollar class:

      class Dollar
         
    {
         
    Dollar multiply_with_rounding(double multiplier);
         
    Dollar add(Dollar another_dollar);
         
    Dollar subtract(Dollar another_dollar);
         
    String to_string(); //
         
    };

    If your language provides the ability to define operators for a class (such as + and -), you can use arithmetic symbols for the corresponding operations. You can also use the appropriate method name to have a Dollar be converted automatically to a String if it appears in an appropriate context. How you represent the abstract data type that you use for a value is an implementation detail. You can make up a class for each type. If you work with C++, you can make up typedefs for each simple type for which there is no additional functionality. For other languages, you can convert some simple types into primitive types. In that case, you might want to use variable names that include the type (e.g., double price_in_dollars).

    WHEN YOU'RE ABSTRACT, BE ABSTRACT ALL THE WAY

    Do not describe data items using primitive data types.

    This guideline suggests using explicit typing in describing the problem and the solution. By using abstract data types in the beginning, you are, in effect, more abstract. If you explicitly type all your attributes and parameters, you can always switch to implicit typing if the explicit typing gets in the way. It is much harder to go in reverse.


    ADTS AND SPEED OF DEVELOPMENT

    I was the chief judge of the Droege Developer Competition. In this event, pairs of developers competed to code a project for a nonprofit organization in one day. They were provided specifications and the results were judged the next day. Developers who used a product from Magic Software (http:// www.magicsoftware.com/) consistently scored high and often won the competition. That product includes the ability to define data types that contain validation rules, display rules (e.g., drop-down lists or radio buttons), and formatting rules. The record layout in the tables is defined using these data types, rather than primitive Structured Query Language (SQL) types. To display a record, the record fields were placed onto the display window. The requisite formatting and validation for each field were already coded. Additional validation could be added when necessary.

    The data typing feature, which is a particular implementation of abstract data typing, was key in the ability to create a working system quickly.


    More Practices Articles
    More By O'Reilly Media


     

    Buy this book now. This article is excerpted from Prefactoring, written by Ken Pugh (O'Reilly; ISBN: 596008740). Check it out today at your favorite bookstore. Buy this book now.

       

    PRACTICES ARTICLES

    - More Techniques for Finding Things
    - Finding Things
    - Finishing the System`s Outlines
    - The System in So Many Words
    - Basic Data Types and Calculations
    - What`s the Address? Pointers
    - Design with ArgoUML
    - Pragmatic Guidelines: Diagrams That Work
    - Five-Step UML: OOAD for Short Attention Span...
    - Five-Step UML: OOAD for Short Attention Span...
    - Introducing UML: Object-Oriented Analysis an...
    - Class and Object Diagrams
    - Class Relationships
    - Classes
    - Basic Ideas

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT