• Post Reply Bookmark Topic Watch Topic
  • New Topic

Identifying the right key for your objects/classes in an application  RSS feed

 
Saikrishnan Srivatsan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I recently had to work on a very simple banking application. Since customers provide their account numbers when they go to the teller to perform a transaction, I chose account number as the key to uniquely identify a customer. To address the fact that a customer can have multiple accounts, I decided to have an entry for every account the customer had, as part of my Teller class, so that he can identify himself with any of his active account numbers. When I was discussing this design with my friend, he felt it was bad and that I had to have a CustomerID field to uniquely identify a customer. I can't seem to understand why we can't do that with account numbers belonging to the customer? Could someone please give an example of where this might not work to help me understand this better?

Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think account number can unique identify a customer. What about a married couple who shares a bank account. You get the account number, but which customer is it?
 
Saikrishnan Srivatsan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jeanne. What if I don't have shared or joint accounts? Could you kindly give me other examples where having an account number will not be appropriate?

If I were to have customer IDs for customers, should I have something like this:

HashMap <customerID, customer>

and then have some means to link account number and customer ID?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saikrishnan Srivatsan wrote:Thanks, Jeanne. What if I don't have shared or joint accounts? Could you kindly give me other examples where having an account number will not be appropriate?

Another example is that the customers bank account is compromised and the customer needs to close it/open a new one. The account number changes, but it is still the same customer.

Saikrishnan Srivatsan wrote:If I were to have customer IDs for customers, should I have something like this:

HashMap <customerID, customer>

and then have some means to link account number and customer ID?

That would work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!