Running on Java 19-ea+23-1706 (Preview)
Home of The JavaSpecialists' Newsletter

1.18 WordLibraries Facade

Juppies 2 by Dr Heinz M. Kabutz

Next we look at the WordLibraries class. Note that this is written in the plural form, which usually means that it is a class that will be used to manage other classes that have something to do with the WordLibrary class that we saw earlier. The correct technical name for this type of class is a Facade, a well-known design pattern that often occurs in Java. The WordLibraries class has a private constructor. So how can we make new objects if the constructor is private? We cannot. That's the point of making the constructor private. The class is also final, although no one would be able to subclass it anyway since the constructor is private. The final on the class is thus a bit redundant. However, it is quite common for a Facade to also be final.

The way that we use the WordLibraries class is to call the static method createDefaultWordLibrary(). Because it is static, we call it on the class itself, not on an object. Thus, when we create our default WordLibrary object we do it simply with: WordLibraries.createDefaultWordLibrary().

In Java, the naming convention is that fields, local variables and parameters to methods typically start with lower case letters and use CamelCase. Classes start with a capital letter and use CamelCase. When I read WordLibraries.createDefaultWordLibrary() I know that this is a method called on a class, thus a static method, without looking at the definition of the method. Please please please please please please please please please please please please please follow this convention in your code. Have classes start with an upper-case letter and fields / local variables / method parameters start with a lower-case letter. Even if you come from a language that does it differently, when coding Java, please use our convention, otherwise you will confuse us horribly when we try to figure out what your code is doing.


When you load these comments, you'll be connected to Disqus. Privacy Statement.

Table of Contents

We hope you enjoyed this tutorial. If you did, you will also enjoy our courses. We suggest you start with Extreme Java - Advanced Java, followed by Extreme Java - Concurrency Performance for Java 8.

About the Author

Heinz Kabutz Java Conference Speaker

Java Champion, author of the Javaspecialists Newsletter, conference speaking regular... About Heinz

Superpack '22

Superpack '22 Our entire Java Specialists Training in one huge bundle more...

Free Java Book

Dynamic Proxies in Java Book
Java Training

We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.

Java Consulting

We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...

Java Emergency?

If your system is down, we will review it for 15 minutes and give you our findings for just 1 € without any obligation.