O'Reilly logo

Java Programming Interviews Exposed by Noel Markham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6

Design Patterns

Software design patterns use one or more objects together to solve a common use case. These use cases often focus on code reuse, extensibility, or generally providing a solid foundation for future development.

Being an object-oriented language, Java makes use of many design patterns throughout the standard library APIs, and it is quite simple to create your own implementation of some common design patterns.

This chapter looks at several common design patterns, examining some of those found in the standard Java APIs, as well as implementing some patterns too.

Hundreds, if not thousands, of software design patterns exist, and you may create some new ones that work for you in your everyday job. The patterns described here are some of the more common and well-known patterns. Interviewers often like asking questions about design patterns, because they provide scope for a lot of discussion, and they have very clear definitions.

Try the examples in this chapter, think of your own scenarios, and see if you can apply the patterns to those, too. Try to justify if a given pattern is good for a given situation, and see if you can make other patterns fit that same situation, too. It won’t always work, but sometimes it is possible for patterns to be interchanged in certain situations.

Investigating Example Patterns

How is the Builder Pattern useful?

When you want to create an object that has many fields, using constructors can become unwieldy and confusing. Imagine ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required