Campbell Ritchie wrote:I do not like nulls...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
You're welcomeSaikrishnan Srivatsan wrote:Thanks Campbell. Do you mean I should think about how I will store my entries? Think about what data structure I'll be using? Or, are there other things that I'm missing in an address book?
Saikrishnan Srivatsan wrote:I thought I'd store my entries like this:
HashMap<Name,Entry> entries = new HashMap<Name, Entry>();
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
That's good, but it should be:-Saikrishnan Srivatsan wrote:I thought I'd store my entries like this:
Campbell Ritchie wrote:it should be:-
Map<Name,Entry> entries = new HashMap<Name, Entry>();
Saikrishnan Srivatsan wrote:
Campbell Ritchie wrote:it should be:-
Map<Name,Entry> entries = new HashMap<Name, Entry>();
I understand the concept of dynamic look-up that Java does but haven't come across a real life example to understand why I really need to declare things the one above as the super type. Is this something that someone can explain or maybe point me to other threads where this has been discussed? I can't understand here whyis bad
Saikrishnan Srivatsan wrote:Why will I not be able to change if I have the implementing type instead of the interface type?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
If I have a Name class, how can I allow multiple contacts to be stored against a name? I am not able to override my hashcode() and equals() appropriately to make this work.Paul Clapham wrote:"Well, why do you need a Name class anyway? Why not just let the Contact object contain the first and last names?" And then one response to that is "Because I might want to have more than one Contact for a Name."
Thank you, Campbell. I still don't need a Name class to do this, correct?Campbell Ritchie wrote:You can have a List<XXX> as the “V” of a Map.
I'll make the constructors public as well.Campbell Ritchie wrote:Why do you have public classes with package‑private constructors?
OK, here's where I was a bit confused. So, is it OK to expose the Name class to the user? If I had a PhoneNumber class, then I'd expose that too? Basically, the user would first use all my "attribute" classes to construct the "attribute" objects and then call the Contact constructor to pass Name, PhoneNumber etc.?Campbell Ritchie wrote:If you have a Name class, why are you not using it in Contact? In that case the validation should be done in
ContactName.
I thought I should be creating my own custom exceptions here. In what cases should I be creating custom exceptions then?Campbell Ritchie wrote:I like the way you are validating names, but surely you would throw an IllegalArgumentException?
I am planning to have one, but I wanted to confirm that I was on the right track before doing too much code.Campbell Ritchie wrote:Don't you have a PhoneNumber class?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |