Ch.2 Flashcards
As the name implies, the main “actors” in the
object-oriented paradigm are called [o..s]. Each
object is an [i..e] of a class. Each class presents
to the outside world a concise and consistent view of
the objects that are instances of this class…
The class definition typically specifies the [d..a
f..s], also known as [i..e v..s], that an
object contains, as well as the [m..s] (operations)
that an object can …
[objects][instance][data fields][instance variables][methods] 60
The notion of [a..n] is to distill a complicated
system down to its most fundamental parts. Typically,
describing the parts of a system involves naming
them and explaining their functionality. Applying the
abstraction…
[abstraction] 62
...paradigm to the design of data structures gives rise to [a..t d..a t..s] (ADTs). An ADT is a mathematical model of a data structure that specifies the type of data stored, the operations supported on them, and the types of parameters of the operations. An ADT specifies [w..t] each operation does, but not [h..w] it does it. In Java, an ADT can be expressed by an [i..e], which is simply a list of method declarations, where each method has an empty body. ... An ADT is is realized by a concrete data structure, which is modeled in Java by a [c..s] ... Also, unlike interfaces, classes specify [h..w] the operations are performed inthe body of each method. A Java class is said to [i..t an i..e] if its methods include all the methods declared in the interface, thus providing a body for them. However, a class can have more methods than those of the interface...
[abstract data types][what][how][interface][class][how][implement an instance] 62
[M..y] refers to an organizing principle in
which different compo-nents of a software system are
divided into separate functional units. Robustness is
greatly increased because it is easier to test and debug
separate components before they are integrated …
[Modularity] 62
Of special relevance to this book is the concept of [d..n p..n], which describes a solution to a
“typical” software design problem. A pattern provides
a general template for a solution that can be applied in
many different situations. It describes the main
elements of a solution in an abstract way that can be
specialized for a …
[design pattern] 64
The PredatoryCreditCard class [a..s] the original CreditCard class, adding a new instance variable named apr to store the annual percentage rate, and adding a new method named processMonth that will assess interest charges. The new class also [s..s] its superclass by [o..g] the original charge method in order to provide a new implementation that assess a ...
[augments][specializes][overriding] 65
We begin with the first line of the class definition, which indicates that the new class inherits from the existing CreditCard class by using Java’s [e..s] keyword followed by the name of its superclass. In Java, each class can extend exactly one other class. Because of this property, Java is said to allow only [s..e i..e] among classes. We should also note that even if a class definition makes no explicit use of the e..s clause, it automatically inherits from a class, java.lang.Object, which serves as the universal superclass ...
[extends][single inheritance][extends] 66
In Java, a constructor of the superclass is invoked
by using the keyword [s..r] with appropriate parameterization, as demonstrated at line 8 of our
implementation:
s..r;
This use of the [s..r] keyword is very similar to
use of the keyword [t..s] when invoking a different
constructor within the same class (as described on
page 15 of Section 1.2.2).
If a constructor for a subclass
does not make an explicit call to [s..r] or [t..s] as its
first command, then an implicit call to [s..r()], the
zero-parameter version of the superclass constructor,
will be made. Returning our attention to the
constructor for PredatoryCreditCard, after calling
the superclass constructor with appropriate
parameters …
[super][super][super][this][super][this][super()] 67
This is permitted precisely because the balance attributed was declared with [p..d] visibility in the original CreditCard class. (See Code Fragment 1.5.)
The most challenging aspect in implementing
the processMonth method is making sure…
[protected] 67
Finally, we consider the new implementation of
the charge method provided for the
PredatoryCreditCard class (lines 21–27). This
definition [o..s] the inherited method. Yet, our
implementation of the new method relies ona call to
the inherited method, with syntax
[s..r].charge(price) at line 22. The return…
[overrides][super] 67
PredatoryCreditCard(…); // parameters omitted
This is a demonstration of what is known as the
[L..v S..n P..e], which states that a
variable (or parameter) with a declared type can be
assigned an instance from any direct or indirect
subclass of that type. Informally, this is a
manifestation of the “is a” relationship modeled by
inheritance, as apredatory credit card is a credit card
(but acredit card is not necessarily predatory).
We say that the variable, card, is [p..c]; it
may take one of many forms, depending on the
specific class of the object to which it refers.
Because card has been declared with type
CreditCard, that variable may only be used to call
methods …
[Liskov Substitution Principle][polymorphic] 68
Java uses a process known as [d..c d..h],
deciding at runtime to call the version of the method
that is most specific to the actual type of the
referenced object (not the declared type). So, if the
object is a PredatoryCreditCard instance, it will
execute the PredatoryCreditCard.charge …
Java also provides an [i..f] operator that
tests, at runtime, whether an instance satisfies as a
particular type. For example, the evaluation of the
boolean condition, (card [i..f]
PredatoryCreditCard), produces [t..e] if cur-rently referenced by the variable card belongs to
the PredatoryCreditCard class …
[dynamic dispatch][instanceof][instanceof][true] 68
Our second example of a specialized progression is
a geometric progression, in which each value is
produced by multiplying the preceding value by a
fixed con-stant, known as the [b..e] of the geometric
progression. The starting point of a geometric
progression is traditionally 1, rather than 0, because
multiplying 0 by any factor results in 0.
[base] 72
A [w..g c..n] occurs when a type T is converted into a “wider” type U. The following are common cases of widening conversions: • T and U are class types and U is a superclass of T...
A [n..g c..n] occurs when a type T is converted into a “narrower” type S. The following are common cases of narrowing conversions: • T and S are class types and Sis a subclass of T. class •T and S are interface types and S is a subinterface of T...
[widening conversion] [narrowing conversion] 88
This is our first example
of an object-oriented design pattern known as the
[c..n d..n p..n]. If we know, for example,
that we want a pair to store a string and a
floating-point number, perhaps to store a stock ticker
label and a price, we could easily design a custom
class for that purpose. However, for another purpose,
we…
[composition design pattern] 91