{ } (braces), 58
+ (plus sign), 62
/ (slash), comment notations using, 69
aborting applications, 54
abstraction
abstract classes
interfaces compared to, 133–135
abstract factory design pattern, 165
abstract methods, 129
nonportable code, 84
accessor methods, 13–14, 73–75
adapter design pattern, 169–171
aggregations
association and, 153
concept of, 112–113, 151–152, 153, 180
Alexander, Christopher, 162
Ambler, Scott, 173
analysis, role in system design, 95
applications
aborting, 54
“The Architecture of Complexity” (Simon), 149
artifacts
Reuseless, 173
Robust, 173
associations
aggregation and, 153
attributes
initialization of, 48
public versus private, 20
static, 83
behavioral inheritance, 63
behavioral patterns
behaviors, object. See also methods
bitwise copies, 64
builder design pattern, 165
buyInventory() method, 142
C / C++ development. See OO (object-oriented) development
C# development. See OO (object-oriented) development
C++ Report, 173
Cabbie class
accessors, 73
comments, 69
constructors
default, 49
name, 68
overloaded methods, 50
CalculateAreas class, 189, 190–191, 192
CalculatePay() method, 14
calling constructors, 48
categories, design pattern, 164–165
chain of response, 171
Circle class, 27–30, 119, 130–131, 189
class diagrams
DataBaseReader class, 51
Dog class, 159
e-business case study, 142–146
CustList class, 143
PizzaShop class, 144
Shop class, 142
classes. See also interfaces; methods; objects
abstract. See also abstraction
interfaces compared to, 133–135
attributes
initialization of, 48
public versus private, 20
Cabbie
accessors, 73
comments, 69
name, 68
overloaded methods, 50
CalculateAreas, 189, 190–191, 192
Circle, 27–30, 119, 130–131, 167–169, 189
comments
notation, 69
number of, 82
composition
aggregations, 112–113, 151–152, 153
associations, 112–113, 152–153, 157–159
definition of, 105
overview of, 30
constructors
calling, 48
injection by, 184
lack of, 71
purpose of, 48
return values, 47
CustList, 143
data hiding, 20
database reader example, 36–40
DataBaseReader
class diagrams, 51
constructors, 52
design guidelines, 10
code reuse, 82
constructors/destructors, 80–81
copying and comparison, 84
extensibility, 83
interaction, 82
maintainability, 86
marshalling, 89
nonportable code, 84
real-world system modeling, 77–78
serialization, 89
top-down, 77
Dog
defining, 134
generalization-specialization, 109–110
Employee
multiple object associations, 157–158
optional associations, 158–159
encapsulation
inheritance weakened by, 115–117
overview of, 20
error handling
applications, aborting, 54
design guidelines, 81
ignoring problems, 54
overview of, 54
Head, 133
highly coupled, 86, 175–177. See also dependencies
identifying, 96
implementation
characteristics of, 36
inheritance
advantages and limitations, 106–109
behavioral, 63
composition as alternative to, 175–177, 179–182
definition of, 105
generalization-specialization, 109–110
implementation, 63
single, 26
weakened by encapsulation, 115–117
interface/implementation paradigm
overview of, 21
interfaces
characteristics of, 36
database reader example, 36–40
extending, 79
IMammal, 197
ISP (Interface Segregation Principle), 197–198
prototypes, 97
Iterator, 172
MailTool, 170
MainApplication, 98
MakingNoise, 200
Mammal, 203
defining, 133
makeNoise() method, 199
Math, 85
messages, 19
Number
Person
attributes, 18
creating, 18
extensibility, 83
methods, 19
PizzaShop, 144
polymorphism
object responsibility, 118–119
overview of, 117
Rectangle, 117, 119, 130–131, 192, 194–197
references, 64
relationships
has-a, 31
setters, injection by, 184
Shape, 165
calcArea() method, 188
factory method design pattern, 165–169
generate() method, 167
ShapeCalculator, 192
Shop, 142
SomeMath, 100
Sound, 101
Star, 119
superclasses, 53
Swimmable, 181
TestBeep, 101
TestFactoryPattern, 169
TestMammal, 200, 201–202, 203–204
TestMath, 100
Whale, 181
Window, 117
code reuse. See also abstraction; object reuse
advantages and limitations, 125
contracts
overview of, 128
as system plug-in points, 138–139
design guidelines for, 82
e-business case study
scenario, 139
interfaces
abstract classes compared to, 133–135
characteristics of, 36
database reader example, 36–40
extending, 79
IMammal, 197
interface/implementation paradigm, 21–23
ISP (Interface Segregation Principle), 197–198
minimum public interface, 78–79
prototypes, 97
terminology, 131
UML diagrams, 132
command design pattern, 171
comments
notation, 69
number of, 82
communication, object-to-object, 10–11
comparing objects, 84
composition, 30
aggregations
association and, 153
concept of, 112–113, 151–152, 153
associations
aggregation and, 153
definition of, 105
dependencies, avoiding, 154–155
example of, 112, 159–160, 179–182
concatenation of strings, 62
consequences, 162
constraints, environmental, 44
constructors
calling, 48
injection, 80
lack of, 71
purpose of, 48
return values, 47
contracts
overview of, 128
as system plug-in points, 138–139
copying objects, 84
“Creating Chaos” (Johnson), 173
creational patterns
categories of, 165
factory method, 165
curly braces ({}), 58
CustList class, 143
customers, 79
data transfer objects (DTOs), 78
DataBaseReader class
class diagram, 51
constructors, 52
databases. See also DataBaseReader class
NoSQL, 89
relational, 89
declaring methods
private implementation methods, 76
public interface methods, 75
decoupling. See dependencies
deep copies, 64
definition inheritance. See inheritance
dependencies, 154–155. See also dependency injection; inheritance
composition, 30
DIP (Dependency Inversion Principle), 3
dependency injection and, 202–204
separating out behavior, 200–202
inheritance
composition as alternative to, 175–177, 179–182
definition of, 198
DIP (Dependency Inversion Principle), 3, 202–204
separating out behavior, 200–202
by parameters, 199
by setter, 184
Dependency Inversion Principle. See DIP (Dependency Inversion Principle)
design
classes, 10
code reuse, 82
constructors/destructors, 80–81
copying and comparison, 84
extensibility, 83
identifying, 96
interaction, 82
maintainability, 86
nonportable code, 84
real-world system modeling, 77–78
error handling, 81
guidelines and best practices
iteration in, 86
marshalling, 89
serialization, 89
top-down design, 77
objects, 12
patterns
advantages of, 162
best practices, 161
elements of, 162
MVC (Model/View/Controller), 163–164
SOLID principles
DIP (Dependency Inversion Principle), 198–204
ISP (Interface Segregation Principle), 197–198
LSP (Liskov Substitution Principle), 194–197
OCP (Open/Close Principle), 192–194
SRP (Single Responsibility Principle), 187–188
system
analysis, 95
class identification, 96
requirements documents, 95
safety versus economics, 94
SOW (statement of work), 95
system prototypes, 96
user interface prototypes, 97
design patterns
advantages of, 162
best practices, 161
elements of, 162
MVC (Model/View/Controller), 163–164
Design Patterns (Gamma et al), 161–162. See also design patterns
diagrams, class
e-business case study, 142–146
CustList class, 143
PizzaShop class, 144
Shop class, 142
diagrams, interface, 132
Dictionary.com, 128
DIP (Dependency Inversion Principle), 3
separating out behavior, 200–202
documentation. See also diagrams, class
amount of, 82
comments
notation, 69
requirements documents, 95
SOW (statement of work), 95
generalization-specialization, 109–110
domains, mixing, 155
DTOs (data transfer objects), 78
e-business case study
scenario, 139
CustList class, 143
PizzaShop class, 144
Shop class, 142
economics, safety versus, 94
Effective C++ (Meyers), 63, 78, 109
Employee class
multiple object associations, 157–158
optional associations, 158–159
Employee object, 14
encapsulation
definition of, 10
inheritance weakened by, 115–117
overview of, 20
enums, 167
environmental constraints, 44
error handling
aborting application, 54
design guidelines, 81
exceptions
ignoring problems, 54
overview of, 54
exceptions
extensibility
design guidelines, 83
interfaces, 79
factory method design pattern, 165–169
flat file systems, 89
fragility, 187
garbage collection, 80
generalization-specialization, 109–110
generateHeat() method, 133
getInventory() method, 142
getMail() method, 171
getSize() method, 133
getSocialSecurityNumber(), 14
Gilbert, Stephen, 115
giveDestination() method, 75, 76
handling errors. See error handling
has-a relationships, 31
hasMoreElements() method, 173
Head class, 133
hiding
data, 9
highly coupled classes, 86, 175–177. See also dependencies
hybrid apps, 7
ignoring problems, 54
IMammal interface, 197
immobility, 187
implementations. See also inheritance
characteristics of, 36
database reader example, 36–40
interface/implementation paradigm
overview of, 21
private implementation methods, 76
inheritance. See also composition; encapsulation
advantages and limitations, 106–109
behavioral, 63
composition as alternative to, 175–177, 179–182
definition of, 105
generalization-specialization, 109–110
implementation, 63
is-a relationships, 107
relationships, 26–27, 131, 135–136, 147
single, 26
weakened by encapsulation, 115–117
init keyword, 47
initialization, attribute, 48
injection, dependency. See dependency injection
interaction, design guidelines for, 82
Interface Segregation Principle (ISP), 3, 197–198
interfaces
abstract classes compared to, 133–135
characteristics of, 36
database reader example, 36–40
extending, 79
IMammal, 197
interface/implementation paradigm, 34–35
overview of, 21
ISP (Interface Segregation Principle), 197–198
prototypes, 97
methods, 75
minimum public interface, 78–79
terminology, 131
UML diagrams, 132
internal customers, 79
interpreter design pattern, 171
Inversion of Control (IoC), 72
IOC (inversion of control), 182
IPS. See Interface Segregation Principle (ISP)
is-a relationships, 26–27, 107, 135–136
ISP (Interface Segregation Principle), 3, 197–198
iterate() method, 173
Iterator class, 172
iterator design pattern, 172–173
Java. See OO (object-oriented) development
Java Design (Coad and Mayfield), 106
Java development. See OO (object-oriented) development
Java Primer Plus (Tyma, Torok, and Downing), 54
Johnson, Johnny, 173
keywords. See also methods
class, 68
init, 47
this, 60
Koenig, Andrew, 173
Larman, Craig, 1
leaks, memory, 81
legacy systems, OO (object-oriented) concepts with, 6–7
Liskov Substitution Principle (LSP), 3, 109, 194–197
LSP. See Liskov Substitution Principle (LSP)
MailTool class, 170
MainApplication class, 98
maintainability, 86
MakingNoise class, 200
Mammal class, 203
defining, 133
makeNoise() method, 199
marshalling objects, 89
Math class, 85
McMarty, Bill, 115
mediator design pattern, 172
memento design pattern, 172
memory leaks, 81
messages, 19
methods, 13. See also keywords
abstract, 129
buyInventory(), 142
CalculatePay(), 14
constructors
calling, 48
injection by, 184
lack of, 71
purpose of, 48
return values, 47
generateHeat(), 133
getInventory(), 142
getMail(), 171
getSize(), 133
getSocialSecurityNumber(), 14
hasMoreElements(), 173
iterate(), 173
overview of, 19
private implementation, 76
public interface, 75
retrieveMail(), 170
setSize(), 133
turnRight(), 76
walk(), 183
minimum public interface, 78–79
mobile web, 7
modeling tools, 15
Model/View/Controller (MVC) design pattern, 163–164
multiple constructors, 49–50, 72
multiple inheritance, 26, 63, 131–132
multiple object associations, 157–158
MVC (Model/View/Controller) design pattern, 163–164
Nameable interface, 132, 136, 137
naming conventions
patterns, 162
new keyword, 47, 53, 165, 169, 181
NoSQL databases, 89
Number class
The Object Primer (Ambler), 86
composition, 30
aggregations, 153
associations, 152–153, 157–159
definition of, 105
dependencies, avoiding, 154–155
example of, 112, 159–160, 179–182
inheritance. See also composition
behavioral, 63
composition as alternative to, 175–177, 179–182
definition of, 105
generalization-specialization, 109–110
implementation, 63
relationships, 147
single, 26
object wrappers
definition of, 7
for nonportable code, 101
Objective-C, 2
Object-Oriented Design in Java (Gilbert and McCarty), 44, 54, 64, 78, 155
object-oriented development. See OO (object-oriented) development
objects. See also classes; methods; object reuse
attributes, 12
initialization of, 48
public versus private, 20
comparing, 84
copying, 84
design, 12
Employee, 14
marshalling, 89
object-to-object communication, 10–11
Payroll, 14
properties, 13
scope
serialization, 89
wrappers
definition of, 7
observer design pattern, 172
OCP. See Open/Close Principle
OO (object-oriented) development, 11. See also abstraction; classes; code reuse; dependencies; objects
abstraction
abstract classes, 121–123, 128–131, 133–135
abstract factory design pattern, 165
abstract methods, 129
nonportable code, 84
comments
notation, 69
number of, 82
composition, 30
aggregations, 112–113, 151–152, 153
associations, 112–113, 152–153, 157–159
definition of, 105
dependencies, avoiding, 154–155
example of, 112, 159–160, 179–182
contracts
overview of, 128
as system plug-in points, 138–139
data hiding, 9
e-business case study
scenario, 139
encapsulation
definition of, 10
inheritance weakened by, 115–117
environmental constraints, 44
error handling
aborting application, 54
design guidelines, 81
ignoring problems, 54
overview of, 54
evolution of, 5
implementations
characteristics of, 36
database reader example, 36–40
interface/implementation paradigm, 21–23
private implementation methods, 76
inheritance
advantages and limitations, 106–109
behavioral, 63
composition as alternative to, 175–177, 179–182
definition of, 105
generalization-specialization, 109–110
implementation, 63
relationships, 131, 135–136, 147
single, 26
weakened by encapsulation, 115–117
interface/implementation paradigm
overview of, 21
interfaces
abstract classes compared to, 133–135
characteristics of, 36
database reader example, 36–40
extending, 79
IMammal, 197
interface/implementation paradigm, 21–23
ISP (Interface Segregation Principle), 197–198
minimum public interface, 78–79
prototypes, 97
terminology, 131
UML diagrams, 132
iteration in, 86
object-to-object communication, 10–11
polymorphism
object responsibility, 118–119
overview of, 117
procedural programming compared to, 7–11
relationships
has-a, 31
scope
SOLID principles
DIP (Dependency Inversion Principle), 198–204
ISP (Interface Segregation Principle), 197–198
LSP (Liskov Substitution Principle), 194–197
OCP (Open/Close Principle), 192–194
SRP (Single Responsibility Principle), 188–191
stacks, 29
Open/Close Principle (OCP), 3, 192–194
optional associations, 158–159
overloading
parameters, injection by, 199
passing references, 71
A Pattern Language (Alexander), 162
patterns, design
advantages of, 162
best practices, 161
elements of, 162
MVC (Model/View/Controller), 163–164
Payroll object, 14
Person class
attributes, 18
creating, 18
extensibility, 83
methods, 19
PizzaShop class, 144
plus sign (+), 62
polymorphism
object responsibility, 118–119
private attributes, 20
private implementation methods, 76
problems, 162
procedural programming
data model, 11
OO (object-oriented) programming compared to, 7–11
properties, object, 13
prototype design pattern, 165
prototypes
system, 96
public attributes, 20
Rectangle class, 117, 119, 130–131, 192, 194–197
references
classes and, 64
passing, 71
relational databases, 89
relationships
has-a, 31
requirements documents, 95
responsibility, SRP (Single Responsibility Principle), 187–188
retrieveMail() method, 170
return values, 47
reuse of code. See code reuse
“Reuse Patterns and Antipatterns” (Ambler), 173
Reuseless Artifact, 173
rigidity, 187
Robust Artifacts, 173
safety, economics versus, 94
scope
separating out behavior, 200–202
serialization, 89
setSize() method, 133
shallow copies, 64
Shape class, 165
calcArea() method, 188
factory method design pattern, 165–169
generate() method, 167
ShapeCalculator class, 192
ShapeType enum, 167
Shop class, 142
Simon, Herbert, 149
single inheritance, 26
Single Responsibility Principle (SRP), 3, 187–188
singleton design pattern, 165
slash (/), 69
Smalltalk
development of, 163
MVC (Model/View/Controller) design pattern, 164–165
DIP (Dependency Inversion Principle)
separating out behavior, 200–202
ISP (Interface Segregation Principle), 197–198
LSP (Liskov Substitution Principle), 194–197
OCP (Open/Close Principle), 192–194
SRP (Single Responsibility Principle), 187–188
solutions, 162
SomeMath class, 100
Sound class, 101
SOW (statement of work), 95
SRP. See Single Responsibility Principle (SRP)
stacks, 29
standalone applications, 39
Star class, 119
state design pattern, 172
statement of work (SOW), 95
static attributes, 83
static keyword, 61–62, 69–71, 74–75
static methods, 83
strategy design pattern, 172
strings, concatenation of, 62
structural patterns
categories of, 169
structured code
substitution, LSP (Liskov Substitution Principle), 194–197
Swift
init keyword, 47
multiple inheritance, 63
scope, 58
Swimmable class, 181
system design
analysis, 95
class identification, 96
for nonportable code, 101
requirements documents, 95
safety versus economics, 94
SOW (statement of work), 95
system prototypes, 96
user interface prototypes, 97
system prototypes, 96
template method, 172
TestBeep class, 101
TestFactoryPattern class, 169
TestMammal class, 200, 201–202, 203–204
TestMath class, 100
TestShape class, 119–121, 190, 191
this keyword, 60
top-down design, 77
troubleshooting. See error handling
turnRight() method, 76
UML (Unified Modeling Language)
class diagrams, 14–15, 19–20, 92
DataBaseReader, 37
interface diagrams, 132
user interface prototypes, 97
users
customers versus, 79
variables, global, 85
visitor design pattern, 172
Visual Basic .NET, 2
multiple inheritance, 63
New keyword, 47
operator overloading, 63
walk() method, 183
Whale class, 181
Window class, 117
word processing framework, 126–127
wrappers
advantages of, 38
for nonportable code, 101
Xerox PARC, 163