The Artima Developer Community
Sponsored Link

News & Ideas Forum (Closed for new topic posts)
See Objects as Bundles of Behavior

2 replies on 1 page. Most recent reply: Mar 6, 2002 10:17 AM by Thomas Taylor

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

See Objects as Bundles of Behavior Posted: Mar 6, 2002 12:46 AM
Reply to this message Reply
Advertisement
"One of the most basic object-oriented ideas is encapsulation -- associating data with code that manipulates the data. The data, stored in instance variables, represents the object's state. The code, stored in instance methods, represents the object's behavior. Because of encapsulation, therefore, you can think of objects as either bundles of data, bundles of behavior, or both. To reap the greatest benefit from encapsulation, however, you should think of objects primarily as bundles of behavior, not bundles of data. You should think of objects less as carriers of information, embodied in the data, and more as providers of services, represented by the behavior.

Why should you think of objects as bundles of services? If data is exposed, code that manipulates that data becomes spread across the program. If higher-level services are exposed, code that manipulates the data is concentrated in one place: the class. This concentration reduces code duplication, localizes bug fixes, and makes it easier to achieve robustness," says this guideline from API Design:

http://www.artima.com/apidesign/object5.html


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: See Objects as Bundles of Behavior Posted: Mar 6, 2002 9:26 AM
Reply to this message Reply
This guideline arises out of my experience going into different companies and seeing their designs. One of the most common things I find is data-oriented design and data-oriented thinking. Data-oriented design is great when you're desiging an XML DTD or a set of relational database tables, but in an OO design, service-oriented thinking is more appropriate. In this guideline, I try to explain why I think that. I try to demonstrate that the benefit of encapsulation is a chance for improved robustness, which you get to the extent that your objects are bundles of services, not bundles of data.

There are many objects that are bundles of data, and should be. I call a big category of these "Messengers," which I talk about a few guidelines later in the chapter.

Comments anyone?

Thomas Taylor

Posts: 3
Nickname: lonebyte
Registered: Feb, 2002

Re: See Objects as Bundles of Behavior Posted: Mar 6, 2002 10:17 AM
Reply to this message Reply
The linkage of services and behaviors of object are powerful concepts. If one extends behavior to services, it prevents packing an object with too many services, adding to an objects complexity both internally and externally.

A "Service_Oriented Mindset" adds clearity to an objects services and its responsibilities.



I've seen the net results of this in bug ridden code as a direct results of poor design and imporper use of objects.

In a side note, I sometimes wish I had your material a year and half ago. Conceptually, undestanding an object and its underlying class structure appears easy. But there is a subtlety which is not that obivious. "a bundle of services" brings it home nicely.

In another note, I have found tackling object design early in my devleopment as a Java programmer, has actually improved and sped up my learning; not to mention the quality of my coding.

Flat View: This topic has 2 replies on 1 page
Topic: Creativity versus Copyright Previous Topic   Next Topic Topic: Objects are for People

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use