11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

112 • Chapter 3: <strong>Programming</strong> with ModulesNote: The remainder of the object oriented version of the Shapes packagecan be read in ShapeObj.mpl file in the samples directory of yourMaple installation.3.6 Interfaces and ImplementationsGeneric programming is a programming style and a software engineeringmethodology for software reuse. In this sense, many Maple built-in operationsare generic. The addition operator + computes sums of integers,rational numbers, complex numbers, polynomials, special functions, andso on. When using the addition operator +, it is not necessary to statehow an expression is represented. (The automatic simplifier recognizeshow Maple expressions are represented.) As with any dynamically typedlanguage, Maple allows for a great deal of generic programming. Mostbuilt-in Maple operations (including many standard library routines) arenaturally polymorphic in that they are able to perform successfully witha large variety of data formats.Generic <strong>Programming</strong> as Good Software Engineering Practice On anylarge project, it is important to write reusable code; that is, code that canperform a well-defined function in a wide variety of situations. Genericprograms do not rely on the details of how their inputs are represented.They are able to perform their function on any inputs that satisfy a specifiedset of constraints. Normally, these constraints are described in termsof the behavior of the inputs rather than on their physical representationor the storage layout of their concrete representation. This behavior issometimes called a contract. Generic programs rely only on the objectbehavior specified by the contract. They do not rely on knowledge of howan object is implemented. So, generic software separates interfaces fromimplementations.Distinction Between Local and Exported Variables The behavior specifiedby the contract for a module includes any module exports. Whateveris expressed through its local variables is private to the module, and isnot to be relied upon, or even known, by clients of the module. (Clientaccess is, in fact, the only technical difference between module locals andexports.)Before the introduction of the module system, design by contract wasenforced in Maple only by convention. Maple routines whose names hadto be enclosed in name quotes (‘) were considered private, and not for

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!