Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Associations and object lifetime

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Says Fowler (p. 57):
"An association represents a permanent link between two objects. That is, the link exists during the whole lives of the objects, although the instances that are connected may change over time."
There seems to be a contradiction between "whole lives" and "may change over time". Consider a Man-Woman association with a 1-1 multiplicity. Let m and w be respective instances associated via this association. Should the link between m and w exist for the whole lifetime of the objects or can the relationship become m'-w or m-w' at some point in time?
Panagiotis.
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Panagiotis,
I believe, the "link exists during the whole lives of the objects", means the reference of the associated object would be permament.
For instance, in the "Catalog" and "Product" case, if the Catalog contains a Product, there would be an attribute defined in the Catalog to hold a Product instance.This represents a permanent link between the two objects.
On the other hand, the Product reference may point to different instances in the Catalog class.This means, the instances may change over time.
To represent as Java code, it would be:

Hope this helps,
Sandeep
[This message has been edited by Desai Sandeep (edited May 20, 2001).]
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see what you mean. It is the _reference_ that is permanent but the referred-to object may change (or even be null as Fowler says).
Makes perfect sense now. Thanks Desai for clarifying this.
Panagiotis.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point. I could also see some design patterns possibly changing the way it actually behaves. i.e. The Male object may be in the married state or single state, where you could use the state pattern to alter his behavior, for example the Male in the married state would be less friendly and more stressed
------------------
David Roberts - SCJP2,MCP
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic