Section 17.7 errata


#1

In 17.7 Loading crimes (CrimeLab.java)

A friend of mine (Charlie Fifield) and myself are working our way threw the book and noticed that the book tells us to add code to

  • public CrimeLab(Contex appContext) {

but what we have in our code is a

  • private CrimeLab(Contex appContext) (
    Note the public vs private above

We checked the source code provided on Big Nerd Ranch’s web site for chapters 17 and 18 and they also show -

  • private CrimeLab(Contex appContext) {
    and in the Chapter 18 (the - Start Chapter 18 Here code) it seems that the section 17.7 code was added to the “private” method, so that’s what were going to do. - Is this correct?

#2

I think that’s correct. If I’m understanding the Java correctly, the constructor is private because to create a CrimeLab from another class you always use the static method CrimeLab.get(). The constructor would have to be public if you were calling it from outside of the class, but because of the singleton design pattern, this is never done. So the private keyword is correct because the constructor is only called from within the class.