Bidirectional association

Hello,
I am designing an application where there are Employee objects and there are WorkBlock objects. A WorkBlock object is simply a block of time that the Employee is scheduled to work.
Each Employee can be scheduled to work one or more WorkBlocks. Each WorkBlock, of course, has one Employee that is assigned to it.
My question is this: I was thinking of having the Employee maintain a List of WorkBlocks that they are assigned to, and also giving a reference to each WorkBlock pointing back to its assigned Employee. This appears to be a bidirectional association, from what I've read in UML book. I thought that this would be a good idea in the long run since you can query the WorkBlock for its Employee and you can query the Employee for its WorkBlocks.
But is this bad code style? Should I instead just have a unidirectional association, and just loop through the entire collection of one item to find the other item?
(For instance, if I only gave WorkBlocks a reference to its Employee, then the only way I could find out which WorkBlocks are assigned to a given employee is to iterate over the entire list of WorkBlocks and look for matching Employees. Does this make sense?)

Erik,
By 'dynamic' I meant that the bidirectional associations can come and go during the lifetimes of the objects involved.
By delegating the job of handling the relationship to something else (the mediator), you can simplify the problem and it's a natural consequence of using the mediator pattern that integrity is maintained. Very nice.
What the mediator does is something like what jschell describes above. How you implement it depends on whether the associations are one-to-one, one-to-many or many-to-many and also it depends on how you want to find or traverse the objects on the other end of the relationship.
Have a look at http://patterndigest.com/patterns/Mediator.html for a quick summary.
One final piece of advice: keep the use of the mediator as an implementation detail shared by the classes that exhibit the bidirectional association. i.e. do not let the rest of the object model become aware of the existence of the mediator. This is often simply a case of getting the object at one end of the association to delegate to the mediator.
Regards,
Lance

Similar Messages

  • Unidirectional vs bidirectional association

    Hi,
    I've read lots of examples and it seems to me that, in reality, these are bidirectional associations:
    Employee and Department (given an employee, you can find out what department(s) s/he belongs to; given a department, you can find out which employees are in it)
    Parent and Child (given a parent, you can find out who are his/her children; given a child, you can find out who his/her parent(s) are)
    Bid and Item (given a bid, you should be able to tell which item it is for; given an item, you can tell which bids were made on it).
    To show unidirectional, the author just omitted the reference to the other in one class. In my opinion, all of the above should be bidirectional (in real life, they would be, I think).
    Can someone give me some real life examples of a unidirectional association?
    Are most associations bidirectional?
    Thanks,
    C

    Hi,
    I've read lots of examples and it seems to me that,
    in reality, these are bidirectional associations:
    Employee and Department (given an employee, you can
    find out what department(s) s/he belongs to; given a
    department, you can find out which employees are in
    it)
    Parent and Child (given a parent, you can find out
    who are his/her children; given a child, you can find
    out who his/her parent(s) are)
    Bid and Item (given a bid, you should be able to tell
    which item it is for; given an item, you can tell
    which bids were made on it).
    To show unidirectional, the author just omitted the
    reference to the other in one class. In my opinion,
    all of the above should be bidirectional (in real
    life, they would be, I think).
    Can someone give me some real life examples of a
    unidirectional association?
    Are most associations bidirectional?You're quite correct - in "real" life, relationships like the ones you cite are bidirectional.
    However, that does not mean that every software representation of real life situation require the bidirectional relationship. If the model you've derived has no need of the many-to-one inverse relationship, it's possible to leave it out. Why do it? If the model doesn't require it, looser coupling.
    If I'm modeling a parent-child relationship in a financial application, the parent has to know about child dependents, but there might not be any reason for the child object to know who their parent is. I only navigate to children objects by accessing the parent first.
    %

  • Unidirectional and Bidirectional association

    Can someone explain the difference between Unidirection association and Bidirectional association.
    An example will be a great help....
    Thanx to all of you.
    Satya

    montefusco,
    I believe you are correct in stating that in an information system (implementation) often there is a unidirectional association between two objects where in the Real World (conceptual) there is a bidirectional association.
    When I mentioned callbacks I was exclusively thinking of an actual callback impelementation.
    In an observer pattern implementation, for example, the Observer object has a reference to the Observable object so that the Observer can register itself to the Observable object. The Observable object has a reference to the Observer object for notifications. (of course there are other ways of implementing this pattern, but you get the point, I hope)
    So, I don't think we contradict each other here. There was just a confusion with coneptual-level class diagrams and implementation-level class diagrams.

  • Neural Nets + Face detection/recognition

    Does anyone have any experience with this, I've been struggling to find decent resources on whether or not building an ANN in Java for this purpose is a reasonable idea or not, even to produce something that wouldn't necessarily, or likely, be massively successful.
    In fact, I've come across very little actual code for this in any programming language so whilst preferring Java, to see any implementation would be interesting for me. I'm aware of JOONE(?) but I suspect that's a relatively mature project and I'd like to see smaller examples of ANNs so I can get some of the concepts first.
    Is it feasible? Are there any online documented instances of people doing this where their code is available? It needs to be *nix too, I did find a link to a VB program but that's not much good as I don't have a Windows box.
    Thanks

    For face detection/recognition, a BAM (Biderectional Associative Memory) neural net would do fine.
    Google for 'Kosko' or ''Bidirectional Associative Memory'. It's quite easy to implement, just a bit
    of matrix multiplications ...
    kind regards,
    Jos

  • Stack trace - NullPointerException

    The following NullPointerException happens when I configure
    destinations with bidirectional one-many associations more than one
    level deep.
    Example:
    Company, one-to-many Vendors, one-to-many Items
    Items, many-to-one Vendor
    The recursive subscription mechanism gets stuck in the Vendor
    association of Item and crashes:
    11:49:53,796 ERROR [STDERR] Exception in RtmpReader thread:
    java.lang.NullPointerException
    11:49:53,796 ERROR [STDERR] java.lang.NullPointerException
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1029)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscriberToSequenceProxies(DataService.java:1044)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.addSubscription(DataService.java:440)
    11:49:53,796 ERROR [STDERR] at
    flex.data.DataService.serviceMessage(DataService.java:298)
    11:49:53,796 ERROR [STDERR] at
    flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:506)
    11:49:53,796 ERROR [STDERR] at
    flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:266)
    11:49:53,796 ERROR [STDERR] at
    flex.messaging.endpoints.rtmp.AbstractRTMPServer.dispatchMessage(AbstractRTMPServer.java: 602)
    11:49:53,796 ERROR [STDERR] at
    flex.messaging.endpoints.rtmp.RTMPConnection$RtmpReader.run(RTMPConnection.java:465)
    11:49:53,796 ERROR [STDERR] at
    edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPo olExecutor.java:643)
    11:49:53,796 ERROR [STDERR] at
    edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolEx ecutor.java:668)
    11:49:53,796 ERROR [STDERR] at java.lang.Thread.run(Unknown
    Source)

    Even with one-level bidirectional associations, FDS evenually
    loops forever when enough records are in the database, and never
    responds to the fill request. I have had to remove all of my
    many-to-one entries from metadata when they point back to the
    owning entity in order to keep working on my application.

  • UML: Rel. with association class having attrib. Are they equivalent?

    Hi All, (and 1M Thanks.)
    Notation:
    _______________ : Bidirection
    1 : cardinality One
    *     : cardinality many
    ................: I draw it to graphically shown the association class AB
    Question 1: Is point 1 and 2 equivalent from the implementation perspective?
    Question 2: Likewise, Is point 3 and 4 equivalent from the implementation perspective?
    1.
    A (1) _______________ (1) B
    ............|
    ............|
    ............AB (association class with an attribute)
    2.
    A (1) _______________ (1) AB (1) _______________ (1) B
    3.
    A (*) _______________ (*) B
    ............|
    ............|
    ............AB (association class with an attribute)
    4.
    A (1) _______________ (*) AB (*) _______________ (1) B

    Association classes imposes that there should only be one connection between two instances, while there is no such limitation in the other case (your comparison between 3 and 4). But there probably won't be any difference between 1 and 2.

  • Conversion of association in ClassDiagram to class definition?

    I have a doubt regarding association in class diagram and actual definition of clasees. Say we have two classes customer and order. Customer can give N orders while one order belongs to one customer. So when we draw the class diagram we can represent this relationship with bidirectional arrow between customer and order with N written on order side and 1 written on customer side .correct?
    Now when we convert this class diagram to actual definition of class, can we simply say customer object will have array of order objects and order object will have a customer object associated with it?
    Now lets change the scenario little bit,order object does not know anything about customer objects. In that case order object will not contain customer, rest will be same as above.
    Is this correct?

    Say we have two classes customer and order. Customer can give N orders while one order belongs to one customer. So when we draw the class diagram we can represent this relationship with bidirectional arrow between customer and order with N written on order side and 1 written on customer side .correct?Yes.
    Now when we convert this class diagram to actual definition of class, can we simply say customer object will have array of order objects and order object will have a customer object associated with it?Well, I'd warn you against three things:
    1) A UML diagram is always, and almost always purposefully, uncomplete: a class diagram represents one aspect of classes, but not necessarily all the features and associations of these classes. You may very well have a diagram that shows a unidirectional association (because for the purpose of what the diagram illustrates, only that direction is meaningful, while another diagram shows an association in the opposite direction, for another purpose.
    I know in your example you already have a bi-directional association, I just want to point out that you do not convert one diagram to code, you merely convert a model (~ a set of diagrams) to code.
    2) Depending on the diagram's intent (e.g. domain class diagram vs design class diagram), not all associations translate to references. For example, depending on how the Customer and Order instances are created, fetched, used,... you might end up with classes that don't even know eachother (and that are simply used jointly by a higher level business logic class, say DatabaseRetriever ). OK that's a bit far-fetched, but again a diagram, especially a class diagram, does not necessarily express code, merely concepts. Again convert the model (set of diagrams), not one single diagram.
    3) A class diagram says little about the business logic of the various classes. Sequence or collaboration diagrams give more insight on the business logic. You might think that the class diagrams translate to structure, and the sequence diagram, to method bodies, but that's not that simple: for example the class diagram does not say whether the number of Order instances may change for a given Customer instance: if so, you'd better use a dynamic collection of orders in that latter, such as a <tt>List<Order></tt> rather than a fixed-length array <TT>Order[]</TT> .
    Again don't convert a diagram, instead convert a model (set of diagrams, both structure diagrams and dynamic diagrams).
    J.

  • Self Association relationship

    hi
    what is Self-Association Relationship?? and could be a Unidirectional or just Bidirectional?
    Thanks

    mshadows wrote:
    hi
    what is Self-Association Relationship?? Never heard the term, but I'm sure the Catholic church would disapprove.
    Can you provide some context?

  • Bidirectional entity access problem (EJB3)

    I made some tests with EJB3 entity beans.
    I have simple entity USERS, where is itself (FK-PK) relation PARENT_ID -> USER_ID.
    Appropriate part of persistent class Users is:
         @ManyToOne
         @JoinColumn(name = "PARENT_ID", referencedColumnName="USER_ID")
         public Users getUsers() {
              return this.users;
         }end servers side:
         @OneToMany(mappedBy="users", cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
         public Set<Users> getUserses() {
              return this.userses;
         }When I do something, specially call setUser(childInstance) to point the parent instance, on MenyToOne side of association it works.
    But when I try to do similar on OneToMany side, like calling:
    getUserses().add(childInstance)or
    getUserses().remove(childInstance)The changes are only transient and there's not saved into the database.
    Although the entity class has bidirectional annotations, it works like unidirectional.
    Thanks for some help
    KM

    In JPA you must always set both sides of the relationship.
    See,
    [http://en.wikibooks.org/wiki/Java_Persistence/Relationships]
    -- James : [http://www.eclipselink.org]

  • Bidirectional object references

    Hi,
    Is it possible to perform bidirectional objectreferences between two object types ? I want to do something like this:
    create type a as object
    ( b_object ref b )
    create type b as object
    ( a_object ref a )
    It should be the same as an association in java.
    thanks

    Hi,
    Is it possible to perform bidirectional objectreferences between two object types ? I want to do something like this:
    create type a as object
    ( b_object ref b )
    create type b as object
    ( a_object ref a )
    It should be the same as an association in java.
    thanks

  • Set file type associations in Adobe Bridge for Photoshop CS6

    Is there a way I can edit the registry so that in Adobe Bridge, under edit, preferences, file type associations, the jpg extension is forced to use the 32-bit version of Photoshop?  I can do it manually, but is there a registry key i can export to apply it to multiple computers?

    Yes, in theory, but it is generally not recommended. But that location would depend on what OS you are on. This video give the locations for the Photoshop files, Bridge would just be in a neighboring folder: http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/how-to-reset-photoshop- cs6s-preferences-file/

  • How do I use cell number associated with iPad 2 3G

    How do I use cell number associated with iPad 2 3G

    For Messages you can can use your email address, the iPad doesn't have a phone number that you can use.

  • Run report that show "BOTH" campaign name AND contact when getting integration error message that relates to Lead Campaign Association

    When running an External Calls Failed report for Lead Campaign Association (e.g.Attempted to add a campaign member where either the member id 00Q70000015ngo5 or the campaign id null is null.), the report show me the contact but not the campaign the contact was trying to associate itself to in SFDC.  In order to see the campaign, I have to click on the downward arrow and click on the "view external call details" FOR EACH INDIVIDUAL CONTACT.
    Is there a report I can run that shows me both the campaign and contact for the error? I can't efficently trouble shoot issues in Eloqua if I have to view each individual record with two or more clicks.
    Any advise?

    I am getting the same error when opening the J2se Development Kit 5.0 Update 8 after I press the Run button. ( "This installation package could not be opened. Verify that the package exists and than you can access it, or contact the application vendor to verify that this is a valid Windows Installer package").
    Is there a solution ?
    Thanks,
    Luck 08/21/06

  • How do I set up family sharing if all my family members emails are already associated with my iTunes account?

    I want to set up family sharing but it won't let me because all the emails are already associated with the one iTunes account we have.  I am afraid to delete because my children use that email address for text messaging.  How do I set up family sharing if all my family members emails are already associated with my iTunes account?

    Hey Wendaroski,
    I am not quite sure what you mean by "my family members emails are already associated with my iTunes account" but what you need for each family member is an Apple ID. Yours would be the one for your iTunes account.
    If the other members of the family already have an Apple ID you can invite them to join the family group. If not they will need to create one, using their email address. This article shows how -
    Set up an Apple ID in iTunes - Apple Support
    Thanks for using Apple Support Communities.
    Be well,
    Brett L 

  • How can I see My Photo Stream from two Macs associated with the same Apple ID?

    I have a MacBook Pro (my personal machine) and an iMac (our family computer).
    The iPhoto library housing all of our family photos lives on the iMac.
    The iPhoto library on my MacBook Pro is currently empty.
    I have an account on both machines.  I have associated the same Apple ID with both machines.
    When I launch iPhoto on my MacBook Pro and attempt to turn on photo sharing (so that I can see My Photo Stream, as well as other shared streams), iPhoto informs me that "iCloud Photos for xxx@xxx is being used with another library named 'iPhoto Library'."
    My iPhone, which is also affiliated with the same Apple ID, shows the streams just fine.
    What can I do to remedy this situation?  I'd like to be able to view my shared streams on my MacBook Pro, while leaving the actual massive photo library on the iMac.

    I found out about this issue when I created a new library with some photo's I wanted to sync to my iCloud account.  I found the following on the Fat Cat Software page and thought it might be helpful to others:
    Using Photo Stream with multiple libraries
    Starting in iPhoto 9.2, Apple introduced a new feature called Photo Stream, which lets you automatically transfer photos via their iCloud service between your iPhoto library and your other devices such as an iPhone, iPad, or another Mac. This feature works when you have multiple iPhoto libraries set up, but there are a couple things to be aware of.
    First, iPhoto will only allow Photo Stream to be active in one iPhoto library at any given time. If you've already enabled Photo Stream in one library, but then open a second library and enable Photo Stream there, this will cause Photo Stream to be turned off in the first library.
    Any photos downloaded by Photo Stream are actually stored in an entirely separate location from any of your iPhoto libraries. This means that, even if you do switch Photo Stream from one library to another, you will not need to go through redownloading all the photos you already have in Photo Stream back from the iCloud servers. So, switching Photo Stream from one library to another is a relatively inexpensive operation, so you can do it as often as needed without it being much of a hassle.

Maybe you are looking for

  • Security Deposit Amount from customer should not be deducted

    Hi, client requirement is Security deposit from Dealer(Customer) should not show the balance of amount of Invoice of the Dealer, It should be shown seperately and not show the balance after deducting Security deposit. This security deposit is returna

  • Apps not remembering which display to use

    I have an iMac with a secondary display. I have Thunderbird on my Secondary display at all times. When I close Thunderbird then reopen, it does not remember to open in the secondary display. How do I fix this?

  • Age Analysis for a GL account?

    Hie All Good day, I have a client who has a unique requirement. They have a general ledger account which shows all Downpayments made. The client requires this account to produce an age analysis for each line item. Is this possible if so how can I ach

  • XP on a G4 with Leopard?

    I was wondering if there is a way to partition my external drive (Time Machine Drive) to run windows XP pro? I know MS has stopped support for VitualPC, so I wanted to know what else is there that can be used? Or if it's possible at all to use the dr

  • T61p & the Nvidia Problem...​...

    So I've been wanting a thinkpad for awhile now..... I finally purchased one on ebay yesterday; a  t61p... But, RIGHT after I paid for it, I started finding stuff out about the Nvidia failure problems.... and of course the one I got has a NVIDIA Quadr