36,59 €
Understand Gang of Four, architectural, functional, and reactive design patterns and how to implement them on modern Java platforms, such as Java 12 and beyond
Key Features
Book Description
Java design patterns are reusable and proven solutions to software design problems. This book covers over 60 battle-tested design patterns used by developers to create functional, reusable, and flexible software.
Hands-On Design Patterns with Java starts with an introduction to the Unified Modeling Language (UML), and delves into class and object diagrams with the help of detailed examples. You'll study concepts and approaches to object-oriented programming (OOP) and OOP design patterns to build robust applications. As you advance, you'll explore the categories of GOF design patterns, such as behavioral, creational, and structural, that help you improve code readability and enable large-scale reuse of software. You'll also discover how to work effectively with microservices and serverless architectures by using cloud design patterns, each of which is thoroughly explained and accompanied by real-world programming solutions.
By the end of the book, you'll be able to speed up your software development process using the right design patterns, and you'll be comfortable working on scalable and maintainable projects of any size.
What you will learn
Who this book is for
If you are a developer who wants to learn how to write clear, concise, and effective code for building production-ready applications, this book is for you. Familiarity with the fundamentals of Java is assumed.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 294
Veröffentlichungsjahr: 2019
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Copyright © 2019 Packt Publishing
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa TripathiAcquisition Editor: Denim Pinto Content Development Editor: Tiksha SarangTechnical Editor: Royce John Copy Editor: Safis EditingProject Coordinator: Prajakta NaikProofreader: Safis EditingIndexer: Rekha NairGraphics: Jisha ChirayilProduction Coordinator: Arvindkumar Gupta
First published: April 2019 Production reference: 1250419
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78980-977-0
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Dr. Edward Lavieri is a veteran software engineer and developer with a strong academic background. He earned a Doctorate of Computer Science from Colorado Technical University, an MS in Management Information Systems (Bowie State University), an MS in Education (Capella University), and an MS in Operations Management (University of Arkansas). He has been creating and teaching computer science courses since 2002. Edward retired from the U.S. Navy as a Command Master Chief after 25 years of active service. He is the founder and creative director of three19, a software design and development studio. Edward has authored more than a dozen technology books, including several on Java.
Aristides Villarreal Bravo is a Java developer, a member of the NetBeans Dream Team, and a Java User Groups leader. He lives in Panama. He has organized and participated in various conferences and seminars related to Java, JavaEE, NetBeans, the NetBeans platform, free software, and mobile devices. He is the author of jmoordb framework, and tutorials and blogs about Java, NetBeans, and web development. He has participated in several interviews about topics such as NetBeans, NetBeans DZone, and JavaHispano. He is a developer of plugins for NetBeans.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Hands-On Design Patterns with Java
Dedication
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Section 1: Introducing Design Patterns
Unified Modeling Language Primer
Technical requirements
Introducing UML
Understanding behavioral UML diagrams
Activity diagrams
Interaction diagrams
Sequence diagrams
Communication diagrams
Timing diagrams
State machine diagrams
Use case diagrams
Understanding structural UML diagrams
Class diagrams
Component diagrams
Composite structure diagrams
Deployment diagrams
Object diagrams
Package diagrams
Summary
Questions
Further reading
Object-Oriented Design Patterns
Technical requirements
Introduction to object-oriented programming
Primary benefits of OOP
Portability
Inheritance
Encapsulation
Polymorphism
Sample OOP class
Instance variables
The this reference
Object-oriented programming approaches
Accessors and mutators
Driver class
Constructors
Overloading constructors and methods
Method call chaining
Principles of design patterns
Creating concise objects
Encapsulating to protect
Being purposeful with inheritance
Learning the complete OOP class
Summary
Questions
Further reading
Section 2: Original Design Patterns
Behavioral Design Patterns
Technical requirements
Introducing behavioral design patterns
Understanding the chain of responsibility pattern
Use case
UML class diagram
Programming the design pattern
University email handler interface
Main email handler
Academic email handler
Alumni email handler
Advising email handler
Finance email handler
HR email handler
Admin email handler
Exploring the command pattern
Use case
UML class diagram
Programming the design pattern
Class variables
Constructor
Accessor methods
Power-related methods
Slider-related methods
Using the interpreter pattern
Use case
UML class diagram
Programming the design pattern
The Expression interface
The MapIntToCharacters class
The Conversion class
InterpreterDriver class
Using the iterator pattern
Use case
UML class diagram
Programming the design pattern
Understanding the mediator pattern
Use case
UML class diagram
Programming the design pattern
Starter
AssemblySystem
Hopper
The SystemAccelerator class
EmergencyBreak
WidgetProductionSystem
Examining the memento pattern
Use case
UML class diagram
Programming the design pattern
Using the null object pattern
Use case
UML class diagram
Programming the design pattern
Observing the observer pattern
Use case
UML class diagram
Programming the design pattern
Understanding the state pattern
Use case
UML class diagram
Programming the design pattern
PrinterOnLine
PrinterOffLine
Printer
PrinterController
Driver
Application output
Strategizing with the strategy pattern
UML class diagram
Understanding the template method pattern
Understanding the visitor pattern
Summary
Questions
Further reading
Creational Design Patterns
Technical requirements
Introducing creational design patterns
Understanding the abstract factory design pattern
Use case
UML class diagram
Programming the design pattern
Interfaces
Abstract Factory class
TypeA classes
TypeB classes
Type-C classes
Driver class
Building with the builder design pattern
Use case
UML class diagram
Programming the design pattern
Roaster class
Interface
Builder classes
Director class
Driver class
Exploring the factory method design pattern
Use case
UML class diagram
Programming the design pattern
Using the prototype design pattern
Use case
UML class diagram
Programming the design pattern
Examining the simple factory design pattern
Use case
UML class diagram
Programming the design pattern
Implementing the singleton design pattern
Use case
UML class diagram
Programming the design pattern
Summary
Questions
Further reading
Structural Design Patterns
Technical requirements
Introduction to structural design patterns
Understanding the adapter design pattern
Use case
UML class diagram
Programming the design pattern
Crossing the bridge design pattern
Learning about abstraction
Implementing the abstraction example
Use case
UML class diagram
Programming the design pattern
Combining objects with the composite design pattern
Use case
UML class diagram
Programming the design pattern
Understanding the decorator design pattern
Use case
UML class diagram
Programming the design pattern
Implementing the facade design pattern
Use case
UML class diagram
Programming the design pattern
Soaring with the flyweight design pattern
Use case
UML class diagram
Programming the design pattern
Implementing the proxy design pattern
Use case
UML class diagram
Programming the design pattern
Summary
Questions
Further reading
Section 3: New Design Patterns
Architectural Patterns - Part I
Introducing architectural patterns
Understanding the blackboard pattern
Coffee shop automation example
Warehouse security bot example
Understanding the broker pattern
University enterprise information system example
Luxury cruise reservation system example
Understanding the client-server pattern
Coffee shop example
Three-tier example
Understanding the event-driven pattern
Event-driven architectural pattern – broker
Event-driven architectural pattern – mediator
Understanding the extract-transform-load pattern
Extract
Transform
Load
Understanding the layered pattern
Traditional operating system layers example
Mobile operating system layers example
Business application layers example
Understanding the master–slave pattern
Single client example
Cloud storage example
Understanding the microkernel pattern
Construction quote example
Optical disc player example
Summary
Questions
Further reading
Architectural Patterns - Part II
Technical requirements
Understanding the microservices pattern
Logistics example
eCommerce example implementation
Understanding the model-view-controller pattern
Book model-view-controller example implementation
Book class
BookView class
The BookController class
The MVCArchitecturalPattern class
Understanding the naked object pattern
Understanding the peer-to-peer pattern
File sharing example implementation
Networking example implementation
Understanding the pipe-filter pattern
Simple transformation example implementation
Complex transformation example implementation
Understanding the serverless pattern
IaaS implementation
PaaS implementation
SaaS implementation
BaaS implementation
MBaaS implementation
FaaS implementation
Understanding the service-oriented pattern
Understanding the space-based pattern
Summary
Questions
Further reading
Functional Design Patterns
Technical requirements
Introducing functional design patterns
Understanding the execute around design pattern
Demonstrated implementation
Understanding the lambda design pattern
Accessing variables
Implementing lambda with a single parameter
Implementing lambda with multiple parameters
Understanding the loan design pattern
Implementing file processing
Understanding the MapReduce design pattern
Input-Map-Output
Input
Map
Output
Input-Map-Reduce-Output
Input
Map
Reduce
Output
Input-Multiple Maps-Reduce-Output
Input
Multiple maps
Input-Map-Combiner-Reduce-Output
Understanding the memoization design pattern
Understanding the streams design pattern
Stream intermediate operations
Stream terminal operations
Programming the streams design pattern
Understanding the tail call design pattern
Programming the tail call design pattern
Summary
Questions
Further reading
Reactive Design Patterns
Technical requirements
Introducing reactive design patterns
Responsive
Resilient
Elastic
Message-driven
Understanding the asynchronous communication design pattern
Implementing the asynchronous communication design pattern
Understanding the autoscaling design pattern
Horizontal scaling
Vertical scaling
Implementing autoscaling
Understanding the bounded queue design pattern
Understanding the bulkhead design pattern
Understanding the caching design pattern
Implementing the caching design pattern in Java
Understanding the circuit-breaker design pattern
Use case
Understanding the event-driven communication design pattern
Understanding the fail-fast design pattern
Programming the design pattern
Introducing a fail event
Understanding the failure-handling design pattern
Failure isolation
Controlled failure
Understanding the fan-out and quickest-reply design pattern
Understanding the idempotency design pattern
Programming the design pattern
Understanding the monitoring design pattern
Understanding the publisher-subscriber design pattern
Understanding the self-containment design pattern
Understanding the stateless design pattern
Use case
UML class diagram
Programming the design pattern
Summary
Questions
Further reading
Assessments
Chapter 1 
Chapter 2 
Chapter 3 
Chapter 4 
Chapter 5 
Chapter 6 
Chapter 7 
Chapter 8 
Chapter 9 
Other Books You May Enjoy
Leave a review - let other readers know what you think
This book was written to provide software engineers, system architects, and software developers a timeless reference and guide on over 60 design patterns. While the examples are provided in Java, the explanations and examples are programming language-agnostic.
In addition to covering behavioral, creational, structural, architectural, functional, and reactive design patterns, this book provides the reader with an introduction to the Unified Modeling Language (UML) and Object-Oriented Programming (OOP). UML is covered with specific focus on behavioral and structural diagrams, as they are used throughout the book to provide a deeper understanding of the featured design-pattern implementations. OOP is covered to provide the reader with an overview or refresher, depending on their experience. Understanding OOP principles is key to understanding how to program in Java.
This book is for software engineers, system architects, and software developers that want to understand the different design patterns and how they can be used to create more efficient and resilient systems. Familiarity with the fundamentals of the Java programming language is expected.
Chapter 1, Unified Modeling Language Primer, provides an introduction to UML and explains how it is used to help communicate class structures, objects, and interactions. Four behavioral diagrams and six structural diagrams are explained, along with examples to help solidify your understanding of these important components in systems design, and their applicability to the design patterns featured in this book.
Chapter 2, Object-Oriented Design Patterns, explores fundamental, intermediate, and advanced concepts and approaches to OOP and their applicability to design patterns. OOP approaches are examined and a complete OOP class serves as an example of how to implement OOP concepts. The principles of design patterns are explored, which will prime you to dive into the design patterns featured in the rest of the book.
Chapter 3, Behavioral Design Patterns, explores behavioral design patterns with a specific focus on the chain of responsibility, command, interpreter, iterator, mediator, memento, null object, observer, state, strategy, template method, and visitor design patterns. This chapter demonstrates how behavioral design patterns focus on how system components interact to form a system.
Chapter 4, Creational Design Patterns, takes a thorough look at the abstract factory, builder, factory method, prototype, simple factory, and singleton design patterns. The exploration of these six creational design patterns demonstrates how they are used to manage objects as they are instantiated.
Chapter 5, Structural Design Patterns, provides detailed information on the adapter, bridge, composite, decorator, facade, flyweight, and proxy structural design patterns. These patterns have either an object scope or class scope and relate to how objects and classes are combined to form a system.
Chapter 6, Architectural Design Patterns – Part I, examines the blackboard, broker, client-server, event-driven, extract-transform-load, layered, master-slave, and microkernel architectural design patterns. These design patterns are explained, as is their applicability to system-level design.
Chapter 7, Architectural Design Patterns –Part II, continues our coverage of architectural design patterns with a specific look at the microservices, model-view-controller, naked objects, peer-to-peer, pipe-filter, serverless, service-oriented, and space-based design patterns.
Chapter 8, Functional Design Patterns, takes a look at functional design and functional programming. The execute around, lambda, loan, MapReduce, memoization, streams, and tail call patterns are examined. The chapter also reviews how functional design patterns use functional programming to solve computational problems and system design challenges.
Chapter 9, Reactive Design Patterns, examines the responsive, resilient, elastic, and message-driven characteristics of reactive design patterns. Specific design patterns covered in this chapter include asynchronous communication, autoscaling, bounded queue, bulkhead, caching, circuit breaker, event-driven communication, fail fast, failure handling, fan-out and quickest reply, idempotency, monitoring, publisher-subscriber, self-containment, and stateless patterns.
The reader should have a familiarity with Java and be capable of writing, compiling, and executing Java applications. In order to execute the examples in this book, the reader should have access to a 64-bit version of Windows 7 (SP1), 8, or 10; a Mac with macOS 10.11 or higher; or a computer running Linux GNOME or KDE desktop.
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packt.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Design-Patterns-with-Java. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781789809770_ColorImages.pdf.
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Next, we have the Mother class, which extends Grandmother and has its own constructor method."
A block of code is set as follows:
Mother() { System.
out
.println(
"Mother constructor executed."
); }}
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
public abstract class
MotorHomeAbstractFactory {
public abstract
Frame createFrame();
public abstract
Style createStyle();
public abstract
Engine createEngine()
;
public abstract
Kitchen createKitchen();}
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Beneath the Receive Order node is a horizontal black bar referred to as a fork."
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.
In this section, you will gain an understanding of the concept and significance of design patterns, learn necessary unified modeling language constructs, and learn how design patterns are classified into a comprehensive library.
The following chapters will be covered:
Chapter 1
,
Unified Modeling Language Primer
Chapter 2
,
Object-Oriented Design Patterns
This book features several design patterns and covers their implementation using Java. We can use Unified Modeling Language (UML) to help communicate class structures, objects, and interactions. This chapter provides an overview of UML, with a specific focus on diagrams applicable to the hands-on activities in this book.
The following topics will be covered in this chapter:
Introducing UML
Behavior diagrams
Structural diagrams
This chapter does not have any technical requirements. In order to create UML diagrams, the following open source software tool is recommended:
Modelio, which is available at
https://www.modelio.org
Modelio can be run on systems with any of the following operating systems:
Debian/Ubuntu
macOS X
RedHat/CentOS
Windows 7
Windows 8
Windows 10
UML was developed in 1994 to document object-oriented systems. Since that time, UML has become a standard tool for software engineers, software developers, and businesses. UML is used to design software and, after programming, also provides a visual record for the system which can be included as part of formal software documentation.
There are two types of UML diagrams—behavioral and structural. Both are described in the sections that follow.
Behavioral diagrams illustrate how system components interact to form a system. The four diagrams listed here are behavioral, and are briefly described in the subsections that follow:
Activity diagrams
Interaction diagrams
State machine diagrams
Use case diagrams
Activity diagrams illustrate the flow of processes in a system. This type of diagram is used to visually document activities within a system, also referred to as a system's procedures or dynamic components.
The following activity diagram shows the activities involved when a coffee shop customer places an order. The starting point is the top black circle. From there, an order is received. Beneath the Receive Order node is a horizontal black bar referred to as a fork. There are three activities that take place in parallel after the fork—Make Drink, Get Bakery, and Collect Payment. All of those activities take place in parallel. Each of those activities feed into a second black bar, this time referred to as a join, which has multiple activities linked to it. Once all three activities are completed, the order can be completed and ends with the bottom black circle:
Interaction diagrams visually document how system components interact with each other.
In the following interaction diagram, you can see that the flow starts with a decision on whether the customer is a new, or already existing, customer. In both cases, the interaction between the Customer object and Customer Database object is documented:
Interaction UML diagrams are robust and come in several different types. The interaction UML diagram types are listed here and will be covered in the subsequent sections:
Sequence diagram
Communication diagram
Timing diagram
Sequence diagrams are used to show a specific use case scenario. So, these diagrams are representative of a typical behavior based on the given use case.
The following sequence diagram example visually documents the use case where a student logs on to an online book order system and enters their course code. The online system calculates a price and provides this total to the student. The student is then able to submit their payment, which goes through the online bookstore and informs the fulfillment center, which ships the books to the student:
Communication diagrams are a special type of interaction diagrams. They focus on how system participants are linked to one another.
The following sample communication UML diagram is a partial look at an online book-ordering system. System participants and their associations are provided:
Timing UML diagrams provide a visual representation of a system's time constraints.
The following example shows two time constraints in a bank's vault security system. There are two objects:
Bio Security System
Vault
Each starts in the Off state. The first time constraint indicates that the vault must be opened within 15 seconds of the Bio Security System being activated. The second time constraint is that the vault can only be open for 20 minutes or less:
State machine diagrams are used to visually describe a system's behavior. The key components of these diagrams include states and transitions. The sample state machine provided in the following diagram is for a bank vault. The solid circle is the initial pseudo state and indicates entry into the system. There are four states—Wait, Unlock, Enable, and Vault.
In our bank vault example, the vault is enabled when two bank managers place their thumb on a thumbprint scanner. The vault is unlocked, contingent on a successful thumbprint scan, by entering the correct combination. When these conditions are met, the Vault state is reached and the managers can enter it:
Use case diagrams document the interactions between your users and your system. This is typically done with text, but UML does support use cases.
Let's start by looking at use cases in text, and then review a UML diagram representing the same use cases. We will use an example of a grade book for an online education institution.
The student logs on to the system and selects their class. The student then selects the assignment and uploads their document. Next, the student enters text and selects the submit button.
The instructor logs on to the system and selects their class. The instructor then selects the assignment, and the student. They grade the assignment, enter a grade, and select the submit button.
These use cases are pretty basic and easy to understand in text. There are only a few constructs for the use case diagram in UML:
There are several visual components to the UML use case diagram:
Actor
: The stick figure is referred to as an actor. In our example, student and instructor were both actors. These are the users that use your system. Often, there are multiple user roles in a system.
Relationship
:
The solid lines indicate which actors interact with which use case items.
System
:
The overall system is represented by a rectangle. Actors are placed outside of the system and use case items are placed within the system.
Use Case Item
:
Use case items are represented in ovals, as seen in our preceding
Online Grade Book
example. These are the components of your use case.
These visual components are further illustrated as follows:
Structural diagrams illustrate components of a system. The six diagrams listed here are structural, and are briefly described in the subsections that follow:
Class diagrams
Component diagrams
Composite structure diagrams
Deployment diagrams
Object diagrams
Package diagrams
The class diagram is the most commonly used UML diagram, as it provides a visual description of a system's objects. Consider that, in Java, everything is an object, so you can see the relevance and reason as to why this particular diagram is so widely used. Class diagrams do more than just display objects—they visually depict their construction and relationships with other classes.
As you can see here, the basic component of the class diagram is a rectangle, divided into three sections. Each overall rectangle represents a class, and the class name appears using a bold typeface in the top section. The middle section contains attributes that correlate to variable fields. The third section contains operation data which, in Java, means functions and methods:
A simple example of a class diagram for a Kennel is displayed in the following diagram. The class name is Kennel, and there are three attributes (animal, breed, and name) and two operations (intake and discharge):
We will further explore class diagrams using our Kennel class example later in this chapter.
Component diagrams provide a visual representation of a system's physical components. The following example illustrates the three physical components of the system:
An inventory database
A customer database
An order component
The relationships between these components are annotated with dotted lines in the following component diagram:
The Composite structure UML diagram shows the runtime structure of a system. This diagram can be used to show the internal components of a class. The following example shows a microwave with four structures:
We can also represent a composite structure with a rectangular box, as illustrated in the following diagram:
Deployment diagrams provide a visual representation of a system's hardware and software. Physical hardware components are illustrated, along with the particular software components that are on them. The hardware components are represented as nodes, and software is represented as an execution environment.
The nodes are drawn as three-dimensional rectangles and represent hardware for a software object, such as a database. As illustrated in the following example, associations are annotated with lines marked with the type of communication protocol used. Our example shows TCP/IP as the communication type:
Deployment diagrams can be more involved than the example provided here. Our example does, however, provide sufficient insight for you to progress through the proceeding chapters.
Object diagrams have an unfortunate name, as it does not aptly describe this UML diagram's purpose. The object diagram visually communicates a set of class instances. In fact, the instances have mostly optional components and are often only partially depicted. Therefore, a more apt name for this diagram might be a loosely defined instance UML diagram.
The following example depicts four objects and their hierarchy. Because each object is an instance of a class, it is underlined and followed by a colon and the class name:
Package diagrams are used to provide a high-level visual depiction of large systems. These diagrams are simplistic and simply show how a system's components are grouped. The following example illustrates nested packages, starting with Java and drilling down to the ArrayList:
The Universal Modeling Language (UML) is used to create visual documentation of our systems. This can be used to design a system as well as document a system. UML is widely used by software engineers, software developers, and other professionals.
Two of the 14 UML diagrams are behavioral and structural. Behavioral diagrams illustrate how system components interact to form a system and include activity diagrams, interaction diagrams, state machine diagrams, and use case diagrams. There are several types of interaction UML diagrams, including sequence diagrams, communication diagrams, and timing diagrams.
Structural diagrams illustrate components of a system and include class diagrams, component diagrams, composite structure diagrams, deployment diagrams, object diagrams, and package diagrams.
In the next chapter, Object-Oriented Design Patterns, we will explore intermediate and advanced concepts and approaches to object-oriented programming and their applicability to design patterns. A review of the fundamental concepts of object-oriented programming will help to ensure a deep conceptual understanding of object-oriented programming. An overview of object-oriented programming-related design pattern principles will also be provided.
What are the two basic types of UML diagrams?
Why was UML initially created?
List four behavioral UML diagrams.
Which UML diagram provides a system's process flow?
Which UML diagram
documents the interactions between a system and its users?
What is a UML actor?
What type of UML diagram illustrates system components?
What
is the most commonly used UML diagram?
Which UML diagram
shows the runtime structure of a system?
Which UML
diagram visually documents a system's hardware and software?
UML 2.0 in Action: A project-based-tutorial
(
https://www.packtpub.com/hardware-and-creative/uml-20-action-project-based-tutorial
)
In this chapter, we will explore intermediate and advanced concepts and approaches to object-oriented programming (OOP) and their applicability to design patterns. We will review the fundamental concepts of OOP to facilitate a deep conceptual understanding. This chapter also covers the principles of OOP design patterns.
Specifically, we will cover the following topics in this chapter:
Introduction to object-oriented programming
Object-oriented programming approaches
Principles of design patterns
Complete OOP class
The code for this chapter can be found at https://github.com/PacktPublishing/Hands-On-Design-Patterns-with-Java/tree/master/Chapter02.
Object-Oriented Programming (OOP
