Introduction to Software Design with Java

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

This textbook provides an in-depth introduction to software design, with a focus on object-oriented design, and using the Java programming language. Its goal is to help readers learn software design by discovering the experience of the design process. To this end, the text follows a continuous narrative that introduces each element of design know-how in context, and explores alternative solutions in that context. This narrative is complemented by hundreds of code fragments and design diagrams.

The first chapter is a general introduction to software design and the subsequent chapters cover design concepts and techniques. The concepts and techniques covered include interfaces, encapsulation, inheritance, design patterns, composition, functional-style design, unit testing, and many more. A major emphasis is placed on coding and experimentation as a necessary complement to reading the text. To support this aspect of the learning process, a companion website with practice exercises is provided, as well as two complete sample applications. Guidance on these sample applications is provided in “Code Exploration” insets throughout the book. Although the Java language is used as a means of conveying design-related ideas, the book’s main goal is to address concepts and techniques that are applicable in a host of technologies.

This second edition covers additional design techniques such as input validation and dependency injection. It also provides extended and revised treatment of many core subjects, including polymorphic copying, unit testing, the Observer pattern, and functional-style programming.

This book is intended for readers who have a minimum of programming experience and want to move from writing small programs and scripts to tackling the development of larger systems. This audience naturally includes students in university-level computer science and software engineering programs. As the prerequisites to specific computing concepts are kept to a minimum, the content is also accessible to programmers with no previous background in computing. In a similar vein, understanding the code fragments requires only a minimal grasp of the Java language, such as would be taught in an introductory programming course.

Author(s): Martin P. Robillard
Edition: 2
Publisher: Springer
Year: 2022

Language: English
Pages: 312
Tags: Software Design; Java; UML; Design Patterns; Object Oriented Programming

Preface
Organization of the Book
Acknowledgments
Contents
Chapter 1 Introduction
1.1 Defining Software Design
1.2 Design in the Software Development Process
1.3 Capturing Design Knowledge
The Unified Modeling Language
1.4 Sharing Design Know-How
Design Patterns
Design Antipatterns
Insights
Further Reading
Chapter 2 Encapsulation
Design Context
2.1 Encapsulation and Information Hiding
2.2 Encoding Abstractions as Types
Code Exploration: JetUML · Dimension
Code Exploration: Solitaire · Card
2.3 Scopes and Accessibility
2.4 Object Diagrams
2.5 Escaping References
Returning a reference to an internal object
Storing an external reference internally
Leaking references through shared structures
2.6 Immutability
Code Exploration: JetUML · Rectangle
2.7 Exposing Internal Data
Extended interface
Returning Copies
Other Strategies
Code Exploration: JetUML · Diagram
Diagram
2.8 Input Validation
Code Exploration: JetUML · Version
2.9 Design by Contract
Code Exploration: JetUML · Rectangle
Code Exploration: Solitaire · Deck
Insights
Further Reading
Chapter 3 Types and Interfaces
Design Context
3.1 Decoupling Behavior from Implementation
3.2 Specifying Behavior with Interface Types
3.3 Class Diagrams
3.4 Function Objects
3.5 Iterators
3.6 The ITERATOR Design Pattern
Code Exploration: Solitaire · CardStack
3.7 The STRATEGY Design Pattern
Code Exploration: Solitaire · PlayingStrategy
PlayingStrategy
3.8 Dependency Injection
Code Exploration: Solitaire · GameModel
3.9 The Interface Segregation Principle
Code Exploration: Solitaire · GameModel
Code Exploration: JetUML · DiagramElement
Insights
Further Reading
Chapter 4 Object State
Design Context
4.1 The Static and Dynamic Perspectives of a Software System
4.2 Defining Object State
4.3 State Diagrams
4.4 Designing Object Life Cycles
Invalid and Useless States
Unnecessary Stateful Information
4.5 Nullability
No Need to Model Absent Values
Modeling Absent Values
Optional Types
Code Exploration: JetUML · TypeNode
The NULL OBJECT Design Pattern
Code Exploration: Solitaire · NullPlayingStrategy
4.6 Final Fields and Variables
4.7 Object Identity, Equality, and Uniqueness
Code Exploration: JetUML · Dimension
4.8 The FLYWEIGHT Design Pattern
Code Exploration: JetUML · Direction
4.9 The SINGLETON Design Pattern
Code Exploration: Solitaire · GameModel
Code Exploration: JetUML · ApplicationResources
4.10 Objects of Nested Classes
Inner Classes
Anonymous Classes
Code Exploration: Solitaire · GameModel
Insights
Further Reading
Chapter 5 Unit Testing
Design Context
5.1 Introduction to Unit Testing
5.2 Unit Testing Framework Fundamentals with JUnit
5.3 Organizing Test Code
5.4 Metaprogramming
Introspection
Program Manipulation
Program Metadata
5.5 Structuring Tests
Code Exploration: Solitaire · TestFoundations
5.6 Tests and Exceptional Conditions
Code Exploration: JetUML · TestDiagramType
5.7 Encapsulation and Unit Testing
Code Exploration: Solitaire · TestTableau
5.8 Testing with Stubs
5.9 Test Coverage
Statement Coverage
Branch Coverage
Path Coverage
Insights
Further Reading
Chapter 6 Composition
Design Context
6.1 Composition and Aggregation
Code Exploration: Solitaire · GameModel
6.2 The COMPOSITE Design Pattern
6.3 Sequence Diagrams
6.4 The DECORATOR Design Pattern
6.5 Combining COMPOSITE and DECORATOR
6.6 Polymorphic Copying
6.7 The PROTOTYPE Design Pattern
Code Exploration: JetUML · DiagramTabToolBar
6.8 The COMMAND Design Pattern
Code Exploration: Solitaire · Move
Code Exploration: JetUML · DiagramOperation
6.9 The Law of Demeter
Code Exploration: Solitaire · GameModel
Insights
Further Reading
Chapter 7 Inheritance
Design Context
7.1 The Case for Inheritance
7.2 Inheritance and Typing
Downcasting
Singly-Rooted Class Hierarchy
7.3 Inheriting Fields
7.4 Inheriting Methods
Annotating Overridden Methods
7.5 Overloading Methods
7.6 Polymorphic Copying with Inheritance
7.7 Inheritance Versus Composition
7.8 Abstract Classes
Code Exploration: JetUML · Edge class hierarchy
7.9 Revisiting the DECORATOR Design Pattern
7.10 The TEMPLATE METHOD Design Pattern
Final Methods and Classes
Abstract Methods
Summary of the Pattern
7.11 Proper Use of Inheritance
Restricting What Clients of Base Classes Can Do
Subclasses That Are Not Proper Subtypes
Code Exploration: JetUML · NodeViewer class hierarchy
Insights
Further Reading
Chapter 8 Inversion of Control
Design Context
8.1 Motivating Inversion of Control
8.2 The Model–View–Controller Decomposition
8.3 The OBSERVER Design Pattern
Linking Model and Observers
Control Flow Between Model and Observers
Data Flow between Model and Observers
Event-Based Programming
Summary of the Pattern
Code Exploration: Solitaire · GameModel
8.4 Applying the OBSERVER Design Pattern
Basic design with Push Data-Flow
Design with Inheritance
Design with Pull Data-Flow
Design with Single Callback and Push/Pull Data-Flow
Code Exploration: JetUML · UserPreferences
8.5 Introduction to Graphical User Interface Development
8.6 Graphical User Interface Component Graphs
The User Experience Perspective
The Source Code Perspective
The Run-time Perspective
Defining the Object Graph
8.7 Event Handling
Code Exploration: Solitaire · Solitaire
Code Exploration: JetUML · EditorFrame
8.8 The VISITOR Design Pattern
Abstract and Concrete Visitors
Integrating Operations into a Class Hierarchy
Traversing the Object Graph
Using Inheritance in the Pattern
Supporting Data Flow in Visitor Structures
Insights
Further Reading
Chapter 9 Functional Design
Design Context
9.1 First-Class Functions
9.2 Functional Interfaces, Lambda Expressions, and Method References
Functional Interfaces
Lambda Expressions
Method References
9.3 Using Functions to Compose Behavior
9.4 Using Functions to Supply, Consume, and Map Objects
Code Exploration: JetUML · Property
9.5 First-Class Functions and Design Patterns
Functional-Style STRATEGY
Code Exploration: Solitaire · GreedyPlayingStrategy
Functional-Style OBSERVER
Code Exploration: JetUML · EditorFrame
9.6 Functional-Style Data Processing
Data as a Stream
Applying Higher-Order Functions to Streams
Filtering Streams
Mapping Data Elements
Reducing Streams
Code Exploration: JetUML · EditorFrame
Insights
Further Reading
Appendix A Important Java Programming Concepts
A.1 Variables and Types
A.2 Objects and Classes
A.3 Static Fields
A.4 Methods
A.5 Packages and Importing
A.6 Generic Types
A.7 Collection Classes
A.8 Exception Handling
Appendix B Coding Conventions
Medial Capitals for Identifier Names
All Capitals for Constants
Variable Name Prefixes
Code blocks, braces, and indentation
Use of the @Override Annotation
Code Comments
Ellipses and Adaptations
Appendix C Sample Applications
Solitaire
JetUML
References
Index