jump to navigation

Clarity occurs at the nth hour May 28, 2008

Posted by javafoo in OOAD, general programming, javanotes, technical design.
add a comment

So I have been trying to put together a design approach document for over a week. I have been struggling to articulate a difficult design concept. I was afraid it was getting too wordsy as it was running over 3 pages. With a mixed audience for the design review, it had to be crisp and not appear as rambling forever. I drafted and re-drafted over the week and knew that with an audience with an attention span of a 2 year old (or is it a 4 year old), I couldn’t get across what I was trying to say.

But with two hours to the meeting, clarity struck. I was replacing paragraphs with patterns, words were just flowing and I had it reduced to 1 page, bullet pointed and all with space to spare. The meeting did actually go well and people got what I was trying to say.  It’s funny how clarity always strikes at the nth hour. Just as the Zen master said.

Capturing n-to-n relationships, Hibernate etc. September 18, 2006

Posted by javafoo in ER - Entity Relationship, OOAD, hibernate, javanotes.
add a comment

So I was trying to capture a one-to-one relationship in Hibernate. I really started thinking about n-to-n relationships and how you can get confused as to where the foreign key goes. I came up with this thumb rule if you have a one-to-many or a many-to-one realtionship the foreign key column id always goes into the “many” end. For ex: I have a one-to-many relationship between Order and OrderLineItem. Since the OrderLineItem is the many end, it will end up holding the Order_id field. So what happens when there is a many-to-many relationship, in that case you have a link table which will hold the primary key ids of both the objects as foreign keys.

Going back to the one-to-one problem, the hibernate config task was not adding the foreign key id, so as a work around I changed it to many-to-one. When I found that it was already mentioned on the hibernate site:

There are two varieties of one-to-one association:

  • primary key associations
  • unique foreign key associations

So I had effectively done option 2.

Also when creating one-to-many relationships there is a caveat. I was running into constraint violations and found this on the hibernate site: “If the <key> column of a <one-to-many> association is declared NOT NULL, Hibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true".” or do away with all foreign key constraints, I opted for the second option.

If only we spend more time on reading documentation. But there’s no better way than learning from mistakes and then struggling to solve them and finally solving them and then realizing that it was already documented. ;-)

Pass by value vs. Pass by reference June 23, 2005

Posted by javafoo in OOAD, java interview, javanotes.
1 comment so far

Always pass by value, if you ever say pass by reference, you will be rejected for sure. (in the interview that is)
You don’t believe me, this guy explains it far more better than I ever can.

Difference between Abstract and Interface June 23, 2005

Posted by javafoo in OOAD, java interview, javanotes.
1 comment so far
  • Interface only provides the contract, does not add default behaviour, whereas abstract classes provide default behaviour (not necessarily, only if you want to, but that is the point)
  • You can implement as many interfaces as you may want, but only extend from one abstract class
  • You cannot have private, protected variables in an Interface.