Java Reference
In-Depth Information
The PendingOrder - Coupon relationship is represented by the PENDING_ORDER
_COUPON table. This table has foreign keys to both the PENDING_ORDER table
and the COUPON table, which stores the coupons. A one-to-many relationship can
also be mapped using a join table, although this approach is used less often
because the foreign key mapping we just described is simpler and faster.
4.1.3
Mapping inheritance
Inheritance is another kind of relationship between classes. This fundamental
object-oriented concept is widely used in domain models. For example, the Food
to Go domain model has the Coupon hierarchy shown in figure 4.2.
In this example, a PendingOrder and an Order can have a Coupon , which is an
interface that encapsulates how to calculate a discount on an order that satisfies
some minimum value. Each concrete implementation of the Coupon interface
implements a different algorithm. The FreeShippingCoupon class provides free
shipping on orders, and the PercentageDiscountCoupon class provides a percent-
age discount. Because relational databases do not directly support inheritance, an
application must map an inheritance hierarchy to one or more tables.
Three main ways exist to map an inheritance hierarchy to a relational schema:
Single table per inheritance hierarchy
Table per class
Table per concrete class
Let's look at each one of these in turn.
<<interface >>
Coupon
PendingOrder
Order
FreeShipping
Coupon
Percentage
DiscountCoupon
code
minimum
code
minimum
percentage
Figure 4.2 The Coupon inheritance hierarchy from the Food to Go
domain model
 
 
 
 
 
 
Search WWH ::




Custom Search