Pace 76 co PO WEEKNAPPLIGATION DEVELOPMENT | SEPTEMBER 11, 1989 O EN APPLIED INTELLIGENCE. — OOP Goes Beyond the Commonsense Meaning of 'Object This is the sec- ond in a series of articles on ob- ject-ortented, technigues, a new technology that's changing the way pro- grammers and tisers deal with computers. When we think of the term "ob- ject," we have an z UAMES — MARYIN NEM intuitive grasp of what that means. In our everyday world, objects have both properties and behaviors: An oven has shape and size; it can bake and broil. The behaviors for responding to the message depend on the values of the variables of a particular object. Object-oriented programming tech nigues are used to invoke the behaviors in an object. For example, the verifica- tion message to an order object would invoke an order behavior that would send a message to an inventory object reguesting the guantity on hand for the item. The inventory object could, in turn, send messages to other objects to obtain the guantity on hand. The benefit of this approach is in- creasingly important as systems get large and complex. Programmers imple- menting the order object do not need'to ( igning which sends the same check reorder tke message to all inventory type objects. The ability of objects to respond to the same message and each implement it ap propriately is called polymorphism. It is one of the aspects of object-oriented pro gramming that simplifies complex code. To better understand polymorphism, let's look at the inventory object. One of its behaviors checks all inventory for items that; might need reordering. It is simple to make a loop that sends the. check-reorder message to each of the in- ventory items in the collection. The code might look like this: global-check-reorder : do i < | to end , check-reorder —> inventory-item(i) This has tremendous implications for program maintainability. As new item to the specific. For example, the po object shown in the fig- ure, the top of the hierarchy might be the abstract object, "collection." It re- sponds to a number of messages, such. as "add an item" and "return an item. It is a general-purpose programming construct that might have been predefined in the system or might be part of a programmer's library of reus- able code. : : 'The programmer implementing the in- ventory object hierarchy might define categories of parts (such as Type A part, Type B part, and so on) as a sub- class of the collection because the inven- tory is a collection of different types of The Hieratehical Atratigement of Oljects Broperties, iiiherited frotn parent objects, becolhe inore specific for edeh stubordihate part. | types are added to the inventory and new procedures for checking reorders are implemented, the code for the inven- tory object never needs to be changed. An object in a program also has prop- erties and behaviors. For example, an order form in a business application has properties such as items and guantity ordered, as well as behaviors such as process and verify. Its easy to see how object-oriented programming can be used to describe environments in which a data-modeling language defines objects and relation: ships. In fact, object-oriented technology originated with languages designed for simulation and is thriving in graphics applications where the user manipulates objects on the screen. However, the for- mal term "object" has meaning beyond the commonsense meaning of the word. The programmer's objects can repre- sent physical entities such as inventory items, but they can also represent more abstract entities such as stacks, num- bers, file-browsers, dispatchers or col- lections. Because it contains both data (proper- ties) and procedures (behaviors), a pro- gramming object can be used to "modularize" any programming concept. Exanples include collections, which are objects made up of other objects, and browsers, which are procedures for ex- amining files. |The properties of an object can't be directly accessed from outside the ob- ject. They are only manipulated by the behaviors of the object. The behaviors of an object can only be invoked by send- ing messages to the object. The imple- inentation of the properties and behaviors of an object is completely hid- žab from the outside. The object's data and processes are enca; ted i the object. z a a To illustrate this, let's look at portions of a simple customer order-entry appli- cation. The system has an object—the order—which has behaviors that allow Mmanipulation and inspection of it prop- ere The definition might look like He Object class: order; variab! Customer, item, guantity; behavlora oi 1y, process, back-order, add, An important distinction needs to be made between a class of objects and particular objects, The definition of the class of object "order" contains defini: tion of the property variables. Each par- (icular object, contains Just the values for the variables of that object. Mes- SaBes are sent to the particular object. Ublečiš tecelva and. tašport to messtgeš. Raorder Policy B ollcy | Policy Policy OOP lets a company program more complexity into the elijkea o Objects This is unlike a conventional application that would need to dispatch the correct reorder procedure for each inventory type. Fine-Tuned Inventory Control In this example, polymorphism, cou- ' pled with both the inheritance of reor- i der policies for standard parts and the ability to customize and override the standard policies for particular parts, al- | lows an organization to program more ! complexity in the reordering logic of a | manufacturing application, thus giving | it more finely tuned inventory control | and a significant competitive advantage. A number of languages are available for programmers interested in experi- menting with object-oriented program- | ming. The oldest and perhaps the purest is Smalitalk, which has some excellent ! implementations on small machines. The system enforces object-oriented pro- | gramming throughout and is an excel- lent tool for learning pure object-orient- | ed programming. | idi Miki j A different approach is to enhance IE Bar z existing languages with object-oriented capabilities. This is the approach taken by C-£-- and Objective-C, which are | both € extensions, as well as Flavors, which is a LISP extension. While this approach provides the familiarity of a 0 Message: || Chieck Inventa uiti Reordet Policy Policy k x K : conventional uage, it has the disad- logic of a manufacturing application, giving it more Jineliy — vantage oi mot forcika the programer t l trol idsi i fi tečem iti i to use object-oriented technigues consis- —— opor: zr know anything about the internal work. ings of the inventory object. They sim- Ply have to know which messages the inventory object will respond to and send those messages to it. i In addition, object-oriented languages allow information to be organized con- ceptually, The object definitions are or- ganized in a class hierarchy, as shown in the figure. A class above an object is its superclass, and the one below is a sub- class. Objects in subelasses can inherit any or all of the properties and behaviors of the classes above. The programmer working with an ob- ject-oriented language defines classes of objects ranging from the general down s) ui SEZ odlo (A The , Programmer must unlearn | e proced programming style that J is so ingrained in anyone with even a | little pi experience. Old pro- gramming habits are hard to break. Next week T'll look at examples of ob- | items, The inventory items in each cate- £ory of parts can themselves be objects, such as serew or bolt. The inventory ob- t rograraming appli ject inherits all the behaviors of the col- REKE ei ; m pora go pd Category object, so no further work from the pro- To learn more about i Sani es Code can add or delete in- these articles, please SNE, a Each of the Inventory types would Via ia pi | updated. guarterly, at (800) 2942-1240. J For information please ka on semina zane Peca Of the parti H contact (in the United ate bid Can- ki lene Check reorder" as it best ada) Tech: er Institute, mi ded s object, or inherit more 741 10th St, Santa Monica, Calif. ge ore r behaviors from 90402 (213) 394-8305. m Europe, con- ek pse b unlexity of diff tact Savant, ? New St, Carnforth, padel es is completely shielded Lancs, LA5 9BX United. Kingdom parts of the full application, (0524) 734 505. rr imo —-